Struts1.x Series Tutorials: built-in standard validation for validator validation framework

Source: Internet
Author: User
Tags regular expression

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.