Class WLengthValidator
public class WLengthValidator extends WValidator
This validator checks whether user input is within the specified range of accepted string lengths.
If you only want to limit the length on a line edit, you may also use WLineEdit#setMaxLength()
.
i18n
The strings used in this class can be translated by overriding the default values for the following localization keys:
- Wt.WLengthValidator.TooShort: The input must be at least {1} characters
- Wt.WLengthValidator.BadRange: The input must have a length between {1} and {2} characters
- Wt.WLengthValidator.TooLong: The input must be no more than {1} characters
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WValidator
WValidator.Result, WValidator.State
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
Constructors Constructor Description WLengthValidator()
Creates a length validator that accepts input of any length.WLengthValidator(int minLength, int maxLength)
Creates a length validator that accepts input within a length range.WLengthValidator(int minLength, int maxLength, WObject parent)
Creates a length validator that accepts input within a length range.WLengthValidator(WObject parent)
Creates a length validator that accepts input of any length. -
Method Summary
Modifier and Type Method Description WString
getInvalidTooLongText()
Returns the message displayed when the input is too long.WString
getInvalidTooShortText()
Returns the message displayed when the input is too short.java.lang.String
getJavaScriptValidate()
Creates a Javascript object that validates the input.int
getMaximumLength()
Returns the maximum length.int
getMinimumLength()
Returns the minimum length.void
setInvalidTooLongText(java.lang.CharSequence text)
Sets the message to display when the input is too long.void
setInvalidTooShortText(java.lang.CharSequence text)
Sets the message to display when the input is too short.void
setMaximumLength(int maxLength)
Sets the maximum length.void
setMinimumLength(int minLength)
Sets the minimum length.WValidator.Result
validate(java.lang.String input)
Validates the given input.Methods inherited from class eu.webtoolkit.jwt.WValidator
getFormat, getInputFilter, getInvalidBlankText, isMandatory, setInvalidBlankText, setMandatory
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setFormData, setObjectName, tr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WLengthValidator
Creates a length validator that accepts input of any length. -
WLengthValidator
public WLengthValidator()Creates a length validator that accepts input of any length.Calls
this((WObject)null)
-
WLengthValidator
Creates a length validator that accepts input within a length range. -
WLengthValidator
public WLengthValidator(int minLength, int maxLength)Creates a length validator that accepts input within a length range.
-
-
Method Details
-
setMinimumLength
public void setMinimumLength(int minLength)Sets the minimum length.The default value is 0.
-
getMinimumLength
public int getMinimumLength()Returns the minimum length.- See Also:
setMinimumLength(int minLength)
-
setMaximumLength
public void setMaximumLength(int maxLength)Sets the maximum length.The default value is the maximum integer value.
-
getMaximumLength
public int getMaximumLength()Returns the maximum length.- See Also:
setMaximumLength(int maxLength)
-
validate
Validates the given input.The input is considered valid only when it is blank for a non-mandatory field, or has a length within the valid range.
- Overrides:
validate
in classWValidator
-
setInvalidTooShortText
public void setInvalidTooShortText(java.lang.CharSequence text)Sets the message to display when the input is too short.Depending on whether
getMaximumLength()
is a real bound, the default message is "The input must have a length between {1} and {2} characters" or " "The input must be at least {1} characters". -
getInvalidTooShortText
Returns the message displayed when the input is too short. -
setInvalidTooLongText
public void setInvalidTooLongText(java.lang.CharSequence text)Sets the message to display when the input is too long.Depending on whether
getMinimumLength()
is different from zero, the default message is "The input must have a length between {1} and {2} characters" or " "The input must be no more than {2} characters". -
getInvalidTooLongText
Returns the message displayed when the input is too long.- See Also:
setInvalidTooLongText(CharSequence text)
-
getJavaScriptValidate
public java.lang.String getJavaScriptValidate()Description copied from class:WValidator
Creates a Javascript object that validates the input.The JavaScript expression should evaluate to an object which contains a
validate(text)
function, which returns an object that contains the following two fields:- fields: a boolean valid,
- a
message
that indicates the problem if not valid.
Returns an empty string if the validator does not provide a client-side validation implementationq.
Note: The signature and contract changed changed in JWt 3.1.9.
- Overrides:
getJavaScriptValidate
in classWValidator
- See Also:
WValidator.getInputFilter()
-