The predefined validation of the validator framework (the version number of struts is 1.2.9) is listed below.
Validator |
Variable |
Raising conditions |
Required |
|
field only spaces |
Validwhen |
Test |
Test condition failed (see next section) |
MinLength |
MinLength |
The number of characters in the field is less than minlength |
MaxLength |
MaxLength |
The number of characters in the field is greater than maxlength |
Mask |
Mask |
The field value does not match a regular expression that mask refers to |
Byte, short, Integer, long, float, double |
|
Field values cannot be converted to these data types |
Date |
Datepattern or Datepatternstrict |
Character value values cannot be converted to date types in the specified format |
Intrange, Floatrange, Doublerange |
Min, max |
field value is not in the specified range |
CreditCard |
|
Field value is not a credit card number |
Email |
|
Field value is not a valid email |
Url |
Allowallschemes,
Allow2slashes,
Nofragments,
Schemes |
field is not a URL |
For more information about validator Framework standard validation, readers can access the following URL:
Http://struts.apache.org/1.2.9/userGuide/dev_validator.html
Here's an example of Validwhen validation.
Validwhen can verify the relationship between the current property and other properties, such as when validating a password, make sure that the password entered two times is identical and the authentication code is as follows:
<field property= "Password1" depends= "Validwhen" >
<msg name= "Validwhen" key= "Error.password1.confirmation"/>
<var>
<var-name>test</var-name>
<var-value>
(password1!= null) and (*this* = = password)
</var-value>
</var>
</field>
You can also use Validwhen to validate nested and indexed properties, as shown in the following code:
<field property= "field1" depends= "Validwhen" >
<msg name= "Validwhen" key= "Error.field.message"/>
<var>
<var-name>test</var-name>
<var-value>
(*this* = = Field2.name) and (*this*!= field3[1])
</var-value>
</var>
</field>
Where *this* represents the value of the current property.