XML-based validator--default.xml provided by the STRUTS2 system

Source: Internet
Author: User
Tags cdata min range regular expression

It programmer development Essentials-all kinds of resources download list, history of the most IT resources, personal collection summary.
These system validators are defined in the Default.xml under Com.opensymphony.xwork2.validator.validators in Xwork-2.x.jar:

<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE validators Public "-//apache struts//xwork Validator Definition 1.0//en" "http://struts.apache.org /dtds/xwork-validator-definition-1.0.dtd "> <!--START snippet:validators-default--<validators> &lt ; Validator Name= "Required" class= "Com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/> < Validator name= "requiredstring" class= "Com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/ > <validator name= "int" class= "Com.opensymphony.xwork2.validator.validators.IntRangeFieldValidator"/> &lt ; Validator name= "Long" class= "Com.opensymphony.xwork2.validator.validators.LongRangeFieldValidator"/> < Validator Name= "Short" class= "Com.opensymphony.xwork2.validator.validators.ShortRangeFieldValidator"/> < Validator Name= "Double" class= "Com.opensymphony.xwork2.validator.validators.DoubleRangeFieldValidator"/> < Validator Name= "Date "class=" Com.opensymphony.xwork2.validator.validators.DateRangeFieldValidator "/> <validator name=" Expression "class=" Com.opensymphony.xwork2.validator.validators.ExpressionValidator "/> <validator name=" Fieldexpression "class=" Com.opensymphony.xwork2.validator.validators.FieldExpressionValidator "/> < Validator name= "Email" class= "com.opensymphony.xwork2.validator.validators.EmailValidator"/> <validator name = "url" class= "Com.opensymphony.xwork2.validator.validators.URLValidator"/> <validator name= "Visitor" class= " Com.opensymphony.xwork2.validator.validators.VisitorFieldValidator "/> <validator name=" Conversion "class=" Com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator "/> <validator name=" Stringlength "class=" Com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator "/> <validator
 Name= "regex" class= "Com.opensymphony.xwork2.validator.validators.RegexFieldValidator"/>   <validator name= "Conditionalvisitor" class= "  Com.opensymphony.xwork2.validator.validators.ConditionalVisitorFieldValidator "/> </validators> <!--
 END Snippet:validators-default--


the system provides the following validator:
Required
(Required validator, required field value cannot be null)
requiredstring(A required String validator, which requires that the value of field cannot be null, and that the length is greater than 0, by default the string is preceded by a space)
Stringlength(The string length validator, which requires that the value of field must be within the specified range, otherwise the checksum fails, the minlength parameter specifies the minimum length, the MaxLength parameter specifies the maximum length, and the trim parameter specifies whether the space before and after the string is removed before verifying the field)
Regex(The regular expression validator checks to see if the field being checked matches a regular expression.) The expression parameter specifies a regular expression, and the CaseSensitive parameter specifies whether the match is case-sensitive, and the default value is true.
int(integer validator, which requires that the integer value of field must be within the specified range, min specifies the minimum value, max specifies the maximum value)
Double(double-precision floating-point validator, which requires a double-precision floating-point number for field must be within a specified range, min specifies the minimum value, max specifies the maximum value)
fieldexpression(Field OGNL expression Validator, which requires field to satisfy a OGNL expression, the expression parameter specifies a OGNL, the logical expression is evaluated based on Valuestack and returns True when the checksum passes, otherwise does not pass)
Email(The mail address checker requires that if the value of field is not NULL, it must be a legitimate e-mail address)
URL(URL validator, required if the value of field is not NULL, it must be a valid URL address)
Date(Date validator, which requires that the date value of field must be within the specified range, min specifies the minimum value, max specifies the maximum value)
Conversion(Conversion validator, specifying the error message when a type conversion fails.)
Visitor(Used to verify the composite property in the action, which specifies that a checksum file is used to verify the properties in the composite property)
expression(The OGNL expression Validator, which specifies the OGNL expression, which evaluates based on Valuestack, returns True if the checksum is passed, otherwise, the validator is not available in the field Validator style configuration)

examples of use of validators

Required Required Calibrator <field-validator type= "required" > <message> gender cannot be empty!</message> </field-validator > requiredstring Required String Validator <field-validator type= "requiredstring" > <param name= "Trim" >true</para M> <message> username cannot be empty!</message> </field-validator> stringlength: string length validator <field-validator t Ype= "Stringlength" > <param name= "maxLength" >10</param> <param name= "MinLength" >2</param&gt
    ; <param name= "Trim" >true</param> <message><! [cdata[product name should be between 2-10 characters]]></message> </field-validator> email: Email Address validator <field-validator type= " Email > <message> Invalid e-mail address </message> </field-validator> regex: Regular expression Validator <field-validator type = "Regex" > <param name= "expression" ><!

[cdata[^1[358]\d{9}$]]></param> <message> Phone number format is incorrect!</message> </field-validator> int: integer validator <field-validator type= "int"> <param name= "min" >1</param> <param name= "Max" >150</param> <message> age must be at 1-1 50 between </message> </field-validator> fields Ognl expression Validator <field name= "ImageFile" > <field-validator type= " Fieldexpression "> <param name=" expression "><! [Cdata[imagefile.length () <= 0]]></param> <message> file cannot be empty </message> </field-validat

 Or> </field>


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.