struts_23_xwork校验器列表使用例子

时间:2022-12-30 16:00:00
required  必填校验器
<field-validator type="required"> <message>性别不能为空!</message> </field-validator>

requiredstring  必填字符串校验器
<field-validator type="requiredstring"> <param name="trim">true</param> <message>用户名不能为空!</message> </field-validator>

stringlength:字符串长度校验器

<field-validator type="stringlength">
    <param name="maxLength">10</param>
    <param name="minLength">2</param>
    <param name="trim">true</param>
    <message><![CDATA[产品名称应在2-10个字符之间]]></message>
</field-validator>

email:邮件地址校验器

<field-validator type="email">
    <message>电子邮件地址无效</message>
</field-validator>

regex:正则表达式校验器

<field-validator type="regex">
     <param name="expression"><![CDATA[^1[358]\d{9}$]]></param>
     <message>手机号格式不正确!</message>
</field-validator>

int:整数校验器

<field-validator type="int">
    <param name="min">1</param>
    <param name="max">150</param>
    <message>年龄必须在1-150之间</message>
</field-validator>

字段OGNL表达式校验器

<field name="imagefile">
    <field-validator type="fieldexpression">
        <param name="expression"><![CDATA[imagefile.length() <= 0]]></param>
        <message>文件不能为空</message>
    </field-validator>
</field>