Struts2 验证

<validators>
<field name="userInfo.uiRealname">
<field-validator type="requiredstring">

<param name="trim">true</param>
<message>真实姓名不允许为空。</message>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">1</param>
<param name="maxLength">50</param>
<message>真实姓名长度必须小于50个字符之间。</message>
</field-validator>
</field>
<field name="userInfo.uiQuestion">
<field-validator type="requiredstring">
<message>密码提示问题必须填写。</message>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">1</param>
<param name="maxLength">100</param>
<message>密码提示问题长度必须小于100个字符之间。</message>
</field-validator>
</field>
<field name="userInfo.uiAge">
<field-validator type="int">
<param name="min">1</param>
<param name="max">100</param>
<message>年龄必须在1-100之间。</message>
</field-validator>
</field>
<field name="userInfo.uiPhone">
<field-validator type="regex">
<param name="expression"><![CDATA[(^(\d{2,4}[-_-—]?)?\d{3,8}([-_-—]?\d{3,8})?([-_-—]?\d{1,7})?$)]]></param>
<message>电话号码必须符合要求!</message>
</field-validator>
</field>
<field name="userInfo.uiHandset">
<field-validator type="regex">
<param name="expression"><![CDATA[(86)*0*13\d{9}]]></param>
<message>手机号码必须符合要求!</message>
</field-validator>
</field>
<field name="userInfo.uiIdcard">
<field-validator type="regex">
<param name="expression"><![CDATA[[\d]{6}(19|20)*[\d]{2}((0[1-9])|(11|12))([012][\d]|(30|31))[\d]{3}[xX\d]*]]></param>
<message>身份证必须符合要求!</message>
</field-validator>
</field>
<field name="userInfo.uiAddress">
<field-validator type="requiredstring">
<message>家庭住址必须填写。</message>
</field-validator>
</field>
<field name="userInfo.uiEmail">
<field-validator type="requiredstring">
<message>电子邮箱必须填写。</message>
</field-validator>
<field-validator type="email">
<message>电子邮箱必须是有效的邮件地址。</message>
</field-validator>
</field>
<field name="userInfo.uiHttp">
<field-validator type="requiredstring">
<message>主页地址不能为空。</message>
</field-validator>
</field>
</validators>

你可能感兴趣的:(struts2)