struts2自带的验证一

stringlength validator

整体说明:stringlength是用来验证一个string field的长度的,通过属性fieldName指定要验证的string field;如果指定了minLengthmaxLength,那么这个string fieldLength就在minLength~maxLength之间;trim属性是调用Stirng.trim()来除去this string field前后的空格的,如果未指定这个属性,this string field依然会被trim()

Example:

<validators> <!-- Plain Validator Syntax --> <validator type="stringlength"> <param name="fieldName">myPurchaseCode</param> <param name="minLength">10</param> <param name="maxLength">10</param> <param name="trim">true</param> <message>Your purchase code needs to be 10 characters long</message> </validator> <!-- Field Validator Syntax --> <field name="myPurchaseCode"> <param name="minLength">10</param> <param name="maxLength>10</param> <param name="trim">true</param> <message>Your purchase code needs to be 10 characters long</message> </field-name> </validators>

 

 

 

requiredstring validator

整体说明:用来验证一个string field是否为空。通过属性fieldName指定要验证的string field; trim属性是调用Stirng.trim()来除去this string field前后的空格的,如果未指定这个属性,this string field依然会被trim()

Example:

<validators> <!-- Plain-Validator Syntax --> <validator type="requiredstring"> <param name="fieldName">username</param> <param name="trim">true</param> <message>username is required</message> </validator> <!-- Field-Validator Syntax --> <field name="username"> <field-validator type="requiredstring"> <param name="trim">true</param> <message>username is required</message> </field-validator> </field> </validators>

 

 

email validator

整体说明:检查一个给定的string field是否为空,是否是一个合法的email;

Example:

<!-- Plain Validator Syntax --> <validators> <validator type="email"> <param name="fieldName">myEmail</param> <message>Must provide a valid email</message> </validator> </validators> <!-- Field Validator Syntax --> <field name="myEmail"> <field-validator type="email"> <message>Must provide a valid email</message> </field-validator> </field>

 

 

 

date validator

整体说明:检查给定的日期是否在一个日期域内,需要注意的是:如果没有给定日期转换格式,XWorkBasicConverter会按照Date.SHORT去格式化日期,如果转换出现问题它会获取系统当前日期。

Example

<validators> <!-- Plain Validator syntax --> <validator type="date"> <param name="fieldName">birthday</param> <param name="min">01/01/1990</param> <param name="max">01/01/2000</param> <message>Birthday must be within ${min} and ${max}</message> </validator> <!-- Field Validator Syntax --> <field name="birthday"> <field-validator type="date"> <param name="min">01/01/1990</param> <param name="max">01/01/2000</param> <message>Birthday must be within ${min} and ${max}</message> </field> </field> </validators>

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值