List of validators provided by struts2

Source: Internet
Author: User
Tags valid email address

The system provides the following validators:
Required (required. The field value cannot be null)
Requiredstring)
Stringlength (String Length validator, which requires that the field value be within the specified range; otherwise, the verification fails. The minLength parameter specifies the minimum length and the maxLength parameter specifies the maximum length, the trim parameter specifies whether to remove spaces before and after the string before verifying the field)
Regex (Regular expression validator, which checks whether the verified field matches a regular expression. The expression parameter specifies the regular expression, and the caseSensitive parameter specifies whether the regular expression is case sensitive when matching. The default value is true)
Int (integer validator, which requires that the integer value of the field be within the specified range, min to specify the minimum value, max to specify the maximum value)
Double (double-precision floating point checker, requires that the field's double-precision floating point number must be within the specified range, min specifies the minimum value, max specifies the maximum value)
Fieldexpression)
Email (the email address checker requires that the field value be a valid email address if it is not empty)
Url (the url validator requires that the field value be a valid url if it is not empty)

Date (date validator, requires that the field date value be within the specified range, min specifies the minimum value, max specifies the maximum value)
Conversion (conversion validator, which specifies the error message prompted when type conversion fails)
Visitor (used to verify the compound attribute in action. It specifies a validation file to verify the attribute in the compound attribute)
Expression (OGNL expression checker. The expression parameter specifies the ognl expression. This logical expression is evaluated based on ValueStack. If true is returned, it is verified. Otherwise, it fails, this validator cannot be used in the style configuration of the field validator)


[Html]
Required
<Field-validator type = "required">
<Message> the gender cannot be blank! </Message>
</Field-validator>
Requiredstring mandatory string validator
<Field-validator type = "requiredstring">
<Param name = "trim"> true </param>
<Message> the user name cannot be blank! </Message>
</Field-validator>

Required
<Field-validator type = "required">
<Message> the gender cannot be blank! </Message>
</Field-validator>
Requiredstring mandatory string validator
<Field-validator type = "requiredstring">
<Param name = "trim"> true </param>
<Message> the user name cannot be blank! </Message>
</Field-validator>
[Html]

[Html]
Stringlength: String Length checker
<Field-validator type = "stringlength">
<Param name = "maxLength"> 10 </param>
<Param name = "minLength"> 2 </param>
<Param name = "trim"> true </param>
<Message> <! [CDATA [product name should be 2-10 characters in length]> </message>
</Field-validator>

Stringlength: String Length checker
<Field-validator type = "stringlength">
<Param name = "maxLength"> 10 </param>
<Param name = "minLength"> 2 </param>
<Param name = "trim"> true </param>
<Message> <! [CDATA [product name should be 2-10 characters in length]> </message>
</Field-validator>
[Html]
Email: email address checker
<Field-validator type = "email">
<Message> the email address is invalid </message>
</Field-validator>
Regex: Regular Expression validator
<Field-validator type = "regex">
<Param name = "expression"> <! [CDATA [^ 1 [358] \ d {9} $]> </param>
<Message> the mobile phone number format is incorrect! </Message>
</Field-validator>

Email: email address checker
<Field-validator type = "email">
<Message> the email address is invalid </message>
</Field-validator>
Regex: Regular Expression validator
<Field-validator type = "regex">
<Param name = "expression"> <! [CDATA [^ 1 [358] \ d {9} $]> </param>
<Message> the mobile phone number format is incorrect! </Message>
</Field-validator>
[Html]
Int: integer validator
<Field-validator type = "int">
<Param name = "min"> 1 </param>
<Param name = "max"> 150 </param>
<Message> the age must be 1-</message>
</Field-validator>

Int: integer validator
<Field-validator type = "int">
<Param name = "min"> 1 </param>
<Param name = "max"> 150 </param>
<Message> the age must be 1-</message>
</Field-validator>
[Html]
 

[Html]
Field OGNL expression validator
<Field name = "imagefile">
<Field-validator type = "fieldexpression">
<Param name = "expression"> <! [CDATA [imagefile. length () <= 0]> </param>
<Message> file cannot be blank </message>
</Field-validator>
</Field>

Field OGNL expression validator
<Field name = "imagefile">
<Field-validator type = "fieldexpression">
<Param name = "expression"> <! [CDATA [imagefile. length () <= 0]> </param>
<Message> file cannot be blank </message>
</Field-validator>
</Field>
[Html]

When the validation file is named ActionClassName-validation.xml, input verification is performed on all the processing methods in the action. If you only need to verify an action Method in the action, then the validation file name should be: ActionClassName-ActionName-validation.xml, where ActionName is the name of the action in struts. xml.


 

Related Article

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.