- Struts 2 教程
- Struts2 - 主页
- Struts2 - 基本 MVC 架构
- Struts2 - 概述
- Struts2 - 环境设定
- Struts2 - 架构
- Struts2 - 示例
- Struts2 - 配置
- Struts2 - 动作
- Struts2 - 拦截器
- Struts2 - 结果类型
- Struts2 - Value Stack/OGNL
- Struts2 - 文件上传
- Struts2 - 数据库访问
- Struts2 - 发送电子邮件
- Struts2 - 验证
- Struts2 - 本地化
- Struts2 - 类型转换
- Struts2 - 主题/模板
- Struts2 - 异常处理
- Struts2 - 注解
- Struts 2 标记
- Struts2 - 控制标记
- Struts2 - 数据标记
- Struts2 - 表单标记
- Struts2 - Ajax 标记
- Struts 2 集成
- Struts2 - Spring
- Struts2 - Tiles
- Struts2 - Hibernate
- Struts 2 有用资源
- Struts2 - 问题与解答
- Struts2 - 快速指南
- Struts2 - 有用资源
- Struts2 - 讨论
基于 XML 的验证器
以下是 Struts2 中提供的各种类型的字段级别和非字段级别验证 −
date 验证器
<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-validator> </field>
double 验证器
<field name = "percentage"> <field-validator type = "double"> <param name = "minExclusive">0.123</param> <param name = "maxExclusive">99.98</param> <message> Percentage needs to be between ${minExclusive} ${maxExclusive} (exclusive) </message> </field-validator> </field>
email 验证器
<field name = "myEmail"> <field-validator type = "email"> <message> Must provide a valid email </message> </field-validator> </field>
expression 验证器
根据提供的正则表达式进行验证的非字段级别验证器。
<field-validator type = "expression"> <param name = "expression">....</param> <message> Failed to meet Ognl Expression .... </message> </field-validator>
int 验证器
<field name = "age"> <field-validator type = "int"> <param name = "min">5</param> <param name = "max">50</param> <message> Age needs to be between ${min} and ${max} </message> </field-validator> </field>
regex 验证器
<field name = "myStrangePostcode"> <field-validator type = "regex"> <param name = "fieldName">myStrangePostcode</param> <param name = "expression"> <![CDATA[([aAbBcCdD][123][eEfFgG][456])]]> </param> </field-validator> </field>
required 验证器
<field name = "username"> <field-validator type = "required"> <message> username must not be null </message> </field-validator> </field>
requiredstring 验证器
<field name = "username"> <field-validator type = "requiredstring"> <param name = "trim">true</param> <message> username must not be null </message> </field-validator> </field>
stringlength 验证器
<field name = "username"> <field-validator type = "stringlength"> <param name = "minLength">10</param> <param name = "maxLength">10</param> <param name = "trim">true</param> <message> Your username needs to be 10 characters long </message> </field-validator> </field>
url 验证器
<field-validator type = "url"> <param name = "fieldName">myHomePageURL</param> <message> Invalid homepage url </message> </field-validator>
struts_validations.htm
广告