Class WLengthValidator
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
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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. -
Method Summary
Modifier and TypeMethodDescriptionReturns the message displayed when the input is too long.Returns the message displayed when the input is too short.Creates a Javascript object that validates the input.int
Returns the maximum length.int
Returns the minimum length.void
Sets the message to display when the input is too long.void
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.Validates the given input.Methods inherited from class eu.webtoolkit.jwt.WValidator
getFormat, getInputFilter, getInvalidBlankText, isMandatory, setInvalidBlankText, setMandatory
-
Constructor Details
-
WLengthValidator
public WLengthValidator()Creates a length validator that accepts input of any length. -
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:
-
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:
-
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
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
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:
-
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.
- Overrides:
getJavaScriptValidate
in classWValidator
- See Also:
-