Class VText
AbstractText-
Constructor Summary
ConstructorsConstructorDescriptionVText(AbstractText field, String errorMessage) Creates a new validator that by default only fails validation if the field's value is empty, that is to say, it's not filled by the user or is filled only with spaces (since spaces are removed before validation). -
Method Summary
Modifier and TypeMethodDescriptionallowEmpty(boolean allow) Checks to see if the field is required to be filled by the user.Ensures that the string is composed of only floating point number characters with optional leading/trailing blanks.Ensures that the string is composed of only integer characters, with optional leading/trailing blanks.setAllowedChars(String chars) Sets the characters allowed in this field.setAllowedPattern(Pattern pat) Sets the regular expression representing the allowed input.setLengthRange(int minlength, int maxlength) Checks to see if the number of chars in the field are between the minimum and maximum amount (both inclusive).setMaxSize(int maxlength) Checks to see if the number of chars in the field are between 0 and the specified maximum amount (inclusive).setMinSize(int minlength) Checks to see if the number of chars in the field are at least the minimum number (inclusive) specified by this method.setUnallowedChars(String chars) Sets the characters not allowed in this field.toString()voidtrimSpaces(boolean val) If set to true, trims the string entered by the user before attempting to run further validation on it.booleanValidates the field in some fashion.Methods inherited from class FieldValidator
getErrorMessage, getField
-
Constructor Details
-
VText
Creates a new validator that by default only fails validation if the field's value is empty, that is to say, it's not filled by the user or is filled only with spaces (since spaces are removed before validation). This can be changed via thetrimSpaces(boolean)method.Other methods in this class can be invoked for further kinds of validation.
-
-
Method Details
-
trimSpaces
If set to true, trims the string entered by the user before attempting to run further validation on it. Defaults to false. [Note: by default, AbstractText fields trim their values anyway so this method is kinda redundant] -
allowEmpty
Checks to see if the field is required to be filled by the user. If the field is allowed to be empty (not filled) and is empty, then validation succeeds and no further validation checks are done.This is useful, for example, if a field is required to be either totally empty or filled with some sort of pattern as specified by
setAllowedPattern(Pattern). Note, however, that this method can get confusing if aVFilledvalidator is also attached to this field (which can be done automatically by database objects generated byGenerate. In that case, 2 error messages will be shown to the user if the field is left blank - one for the attached VFilled validator and one for this one.- Parameters:
allow- true to allow for an empty field false otherwise (defaults to true).- Returns:
- this object for method chaining convenience
-
allowIntegersOnly
Ensures that the string is composed of only integer characters, with optional leading/trailing blanks. This is a convenience method that sets the pattern to be "\s*\d*\s*" -
allowFloatingOnly
Ensures that the string is composed of only floating point number characters with optional leading/trailing blanks. This is a convenience method that sets the pattern to be "\s*-?\d*\.?\d*\s*" -
setLengthRange
Checks to see if the number of chars in the field are between the minimum and maximum amount (both inclusive). If the minimum and maximum amounts are the same (including 0), then the field has to be exactly that length. (empty fields are also allowed if set viaallowEmptymethod.- Returns:
- this object for method chaining convenience
-
setMaxSize
Checks to see if the number of chars in the field are between 0 and the specified maximum amount (inclusive). [this method calls invalid input: '{@link setLengthRange(0, maxlength)'}]- Returns:
- this object for method chaining convenience
-
setMinSize
Checks to see if the number of chars in the field are at least the minimum number (inclusive) specified by this method.- Returns:
- this object for method chaining convenience
-
setUnallowedChars
Sets the characters not allowed in this field. If some character is marked as both allowed (via thesetAllowedChars(java.lang.String)method) and unallowed (via this method), then unallowed characters have precedence and if found in the input, the field will not be validated.The same functionality can be achieved via regular expressions and negated character classes. It's a matter of preference.
After this method is called, the pattern previously set (if any) via the
setAllowedPattern(Pattern)method will be ignored for validation.- Parameters:
chars- the unallowed chars. This parameter must not be null.- Returns:
- this object for method chaining convenience
-
setAllowedChars
Sets the characters allowed in this field. All characters in the specified string will be allowed, all else disallowed. An empty string (no characters at all) is allowed at validation time if set viaallowEmptymethod.After this method is called, the pattern previously set (if any) via the
setAllowedPattern(Pattern)method will be ignored for validation.- Parameters:
chars- the allowed chars. This parameter must not be null.- Returns:
- this object for method chaining convenience
-
setAllowedPattern
Sets the regular expression representing the allowed input. The pattern will be matched with the entire value of the field.After this method is called, the string previously set (if any) via the
setAllowedChars(String)method will be ignored for validation.- Parameters:
pat- the allowed pattern. Must not be null.- Returns:
- this object for method chaining convenience
-
toString
-
validate
Description copied from class:FieldValidatorValidates the field in some fashion.If there are validation error, stores the error in the formdata and returns false, otherwise returns true
- Specified by:
validatein classFieldValidator
-