zoukankan      html  css  js  c++  java
  • Struts2 基于XML校验(易百教程)

    以下是的各类字段级和非字段级验证在Struts2列表:

    date validator:

    <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 validator:

    <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 validator:

    <field name="myEmail">
    <field-validator type="email">
       <message>
          Must provide a valid email
       </message>
    </field-validator>
    </field>

    expression validator:

    非现场级验证,验证基于正则表达式提供。

    <field-validator type="expression">
       <param name="expression">....</param>
       <message>
          Failed to meet Ognl Expression  .... 
       </message>
    </field-validator>

    int validator:

    <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 validator:

    <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 validator:

    <field name="username">
    <field-validator type="required">
       <message>
           username must not be null
       </message>
    </field-validator>
    </field>

    requiredstring validator:

    <field name="username">
    <field-validator type="requiredstring">
     <param name="trim">true</param>
       <message>
           username must not be null
       </message>
    </field-validator>
    </field>

    stringlength validator:

    <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 validator:

    <field-validator type="url">
       <param name="fieldName">myHomePageURL</param>
       <message>
             Invalid homepage url
       </message>
    </field-validator>

     

  • 相关阅读:
    MongoDB的查询
    商品订购及货物采购信息系统(代码分析)
    Java连接数据库(mysql,sqlserver)
    开通博客第一天
    Ubuntu下java环境的搭建
    商品订购及货物采购信息系统(需求分析)
    GitHub客户端发布托管代码
    property中copy和strong修饰符的使用指北
    iOS界面间传值
    GPUImage的滤镜功能一览表
  • 原文地址:https://www.cnblogs.com/pingxin/p/p00009.html
Copyright © 2011-2022 走看看