Struts2 基於XML校驗
以下是的各類字段級和非字段級驗證在Struts2列表:
date validator:
<field name="birthday"> <field-validator type="date"> <param name="min">01/01/1990 <param name="max">01/01/2000
double validator:
<field name="percentage"> <field-validator type="double"> <param name="minExclusive">0.123 <param name="maxExclusive">99.98
${maxExclusive} (exclusive)
email validator:
<field name="myEmail"> <field-validator type="email">
expression validator:
非現場級驗證,驗證基於正則表達式提供。
<field-validator type="expression"> <param name="expression">....
int validator:
<field name="age"> <field-validator type="int"> <param name="min">5 <param name="max">50
regex validator:
<field name="myStrangePostcode"> <field-validator type="regex"> <param name="fieldName">myStrangePostcode <param name="expression"> <![CDATA[([aAbBcCdD][123][eEfFgG][456])]]>
required validator:
<field name="username"> <field-validator type="required">
requiredstring validator:
<field name="username"> <field-validator type="requiredstring"> <param name="trim">true
stringlength validator:
<field name="username"> <field-validator type="stringlength"> <param name="minLength">10 <param name="maxLength">10 <param name="trim">true
url validator:
<field-validator type="url"> <param name="fieldName">myHomePageURL