struts2宣告式驗證 field-validator 的 type 屬性有哪些取值, 代表什麼含義
阿新 • • 發佈:2019-02-05
- <validators>
- <field name="user.userName">
- <!-- 驗證字串不能為空 -->
- <field-validator type="requiredstring">
- <!-- 去空格 -->
- <param name="trim">true</param>
- <!-- 錯誤提示資訊 -->
- <message>使用者名稱不能為空</message>
- </field-validator>
- <!-- 驗證字串長度 -->
- <field-validator type="stringlength">
- <param name="minLength">2</param>
- <param name="maxLength">20</param>
- <message>使用者名稱長度應在2到18個字元間</message>
- </field-validator>
- </field>
- <field name="user.password"
- <field-validator type="requiredstring">
- <param name="trim">true</param>
- <message>密碼不能為空</message>
- </field-validator>
- <field-validator type="stringlength">
- <param name="minLength">6</param>
- <param name="maxLength"
- <message>密碼長度應在6到18個字元之間</message>
- </field-validator>
- </field>
- <field name="user.age">
- <field-validator type="int">
- <param name="min">1</param>
- <param name="max">150</param>
- <message>年齡應在1到150之間</message>
- </field-validator>
- </field>
- <!-- 驗證字串為日期型別 -->
- <field name="user.birthday">
- <field-validator type="date">
- <param name="min">1900-01-01</param>
- <param name="max">2008-10-16</param>
- <message>出生日期應在1900-01-01到2008-10-16</message>
- </field-validator>
- </field>
- </validators>