public final class VText extends FieldValidator
AbstractText
Constructor and Description |
---|
VText(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).
|
Modifier and Type | Method and Description |
---|---|
VText |
allowEmpty(boolean allow)
Checks to see if the field is required to be filled by the user.
|
VText |
allowFloatingOnly()
Ensures that the string is composed of only floating point number
characters with optional leading/trailing blanks.
|
VText |
allowIntegersOnly()
Ensures that the string is composed of only integer characters, with
optional leading/trailing blanks.
|
VText |
setAllowedChars(String chars)
Sets the characters allowed in this field.
|
VText |
setAllowedPattern(Pattern pat)
Sets the regular expression representing the allowed input.
|
VText |
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).
|
VText |
setMaxSize(int maxlength)
Checks to see if the number of chars in the field are between 0 and the
specified maximum amount (inclusive).
|
VText |
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.
|
VText |
setUnallowedChars(String chars)
Sets the characters not allowed in this field.
|
String |
toString() |
void |
trimSpaces(boolean val)
If set to true, trims the string entered by the user before
attempting to run further validation on it.
|
boolean |
validate(FormData fd,
javax.servlet.http.HttpServletRequest req)
Validates the field in some fashion.
|
getErrorMessage, getField
public VText(AbstractText field, String errorMessage)
trimSpaces(boolean)
method.
Other methods in this class can be invoked for further kinds of validation.
public void trimSpaces(boolean val)
public VText allowEmpty(boolean allow)
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(java.util.regex.Pattern)
. Note, however, that this method can get confusing if
a VFilled
validator is also attached to this field (which can be
done automatically by database objects generated by Generate
. 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.
allow
- true to allow for an empty field
false otherwise (defaults to
true).public VText allowIntegersOnly()
public VText allowFloatingOnly()
public VText setLengthRange(int minlength, int maxlength)
allowEmpty
method.public VText setMaxSize(int maxlength)
setLengthRange(0, maxlength)
]public VText setMinSize(int minlength)
public VText setUnallowedChars(String chars)
setAllowedChars
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(java.util.regex.Pattern)
method will be ignored for validation.
chars
- the unallowed chars. This parameter must not be null.public VText setAllowedChars(String chars)
allowEmpty
method.
After this method is called, the pattern previously set (if any) via the
setAllowedPattern(java.util.regex.Pattern)
method will be ignored for validation.
chars
- the allowed chars. This parameter must not be null.public VText setAllowedPattern(Pattern pat)
After this method is called, the string previously set (if any) via the
setAllowedChars(java.lang.String)
method will be ignored for validation.
pat
- the allowed pattern. Must not be null.public boolean validate(FormData fd, javax.servlet.http.HttpServletRequest req)
FieldValidator
If there are validation error, stores the error in the formdata and returns false, otherwise returns true
validate
in class FieldValidator