struts2的校验的xml文件基本配置


Struts2提供了校验机制,一些基本的配置信息如下:



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE validators PUBLIC 
                "-//OpenSymphony Group//XWork Validator 1.0//EN" 
                "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
                
<!-- START SNIPPET: fieldValidatorsExample -->                  
                
<validators>
        <field name="requiredValidatorField">
                <field-validator type="required">
                        <message><![CDATA[ 必填 ]]></message>
                </field-validator>
        </field>
        <field name="requiredStringValidatorField">
                <field-validator type="requiredstring">
                        <param name="trim">true</param>
                        <message><![CDATA[ 必填而且必须是字符串 ]]></message>
                </field-validator>
        </field>
        <field name="integerValidatorField">
                <field-validator type="int">
                        <param name="min">1</param>
                        <param name="max">10</param>
                        <message><![CDATA[ 要求>= 1而且<=10 ]]></message>
                </field-validator>
        </field>
        <field name="dateValidatorField">
                <field-validator type="date">
                        <param name="min">01/01/1990</param>
                        <param name="max">01/01/2000</param>
                        <message><![CDATA[ 必须在1990年1月1日到2000年1月1日之间 ]]></message>
                </field-validator>
        </field>
        <field name="emailValidatorField">
                <field-validator type="email">
                        <message><![CDATA[ 必须是合法的email地址 ]]></message>
                </field-validator>
        </field>
        <field name="urlValidatorField">
                <field-validator type="url">
                        <message><![CDATA[ 必须是合法的URL ]]></message>
                </field-validator>
        </field>
        <field name="stringLengthValidatorField">
                <field-validator type="stringlength">
                        <param name="maxLength">4</param>
                        <param name="minLength">2</param>
                        <param name="trim">true</param>
                        <message><![CDATA[ 字符串长度必须大于1小于5 ]]></message>
                </field-validator>
        </field>
        <field name="regexValidatorField">
                <field-validator type="regex">
                        <param name="expression">.*\.txt</param>
                        <message><![CDATA[ 必须匹配正则表达式 (.*\.txt) ]]></message>
                </field-validator>
        </field>
        <field name="fieldExpressionValidatorField">
                <field-validator type="fieldexpression">
                        <param name="expression">(fieldExpressionValidatorField == requiredValidatorField)</param>
                        <message><![CDATA[ 必须和必填字段值一致 ]]></message>
                </field-validator>
        </field>
</validators>

你可能感兴趣的:(xml,正则表达式)