struts2为name属性指定了两条验证规则,为什么只有一条规则requiredstring起作用,而regex规则不起作用?
struts2为name属性指定了两条验证规则,为什么只有一条规则requiredstring起作用,而regex规则不起作用?<!DOCTYPEvalidatorsPU...
struts2为name属性指定了两条验证规则,为什么只有一条规则requiredstring起作用,而regex规则不起作用?
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<field name="name">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>用户名不能为空!</message>
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{4,8})]]></param>
<message>你输入的用户名只能是字母和数字,且长度在4到8之间</message>
</field-validator>
</field>
<field name="pass">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>密码不能为空!</message>
</field-validator>
</field>
<field name="age">
<field-validator type="int">
<param name="min">1</param>
<param name="max">150</param>
<message>年龄必须要在1到150之间</message>
</field-validator>
</field>
<field name="birth">
<field-validator type="date">
<param name="min">1900-01-01</param>
<param name="max">2050-02-21</param>
<message>生日必须要在${min}到${max}之间</message>
</field-validator>
</field>
</validators> 展开
<!DOCTYPE validators PUBLIC
"-//Apache Struts//XWork Validator 1.0.3//EN"
"http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
<validators>
<field name="name">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>用户名不能为空!</message>
</field-validator>
<field-validator type="regex">
<param name="expression"><![CDATA[(\w{4,8})]]></param>
<message>你输入的用户名只能是字母和数字,且长度在4到8之间</message>
</field-validator>
</field>
<field name="pass">
<field-validator type="requiredstring">
<param name="trim">true</param>
<message>密码不能为空!</message>
</field-validator>
</field>
<field name="age">
<field-validator type="int">
<param name="min">1</param>
<param name="max">150</param>
<message>年龄必须要在1到150之间</message>
</field-validator>
</field>
<field name="birth">
<field-validator type="date">
<param name="min">1900-01-01</param>
<param name="max">2050-02-21</param>
<message>生日必须要在${min}到${max}之间</message>
</field-validator>
</field>
</validators> 展开
1个回答
2014-10-11
展开全部
先在java里面验证一下这个规则表达式起作用了吗
追问
我已经自己找到解决方法了,应该改为
你输入的用户名只能是字母和数字,且长度在4到8之间
这样就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询