validator-rules.xml已经写好了常用的校验,你可以在这个文件里添加自己的校验方法

解决方案 »

  1.   

    正则表达式也可以看明白的(呵呵`~部分部分)象暗码一样。那ruler你用就是了 一定好用的。
     Validator中javascript的使用1.    在struts-config.xml中加入validator的plug-in.  <!-- Validator的配置-->  <plug-in className="org.apache.struts.validator.ValidatorPlugIn"><set-property property="pathnames"value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>  </plug-in> 2.在文件/WEB-INF/validation.xml中是我们要定义自己的验证规则 <form-validation>    <!-- ========== Default Global Definitions ===================== -->
         <global>
          <constant>
            <constant-name>userID</constant-name>
            <constant-value>^\d{5}\d*$</constant-value>
          </constant>
          <constant>
            <constant-name>password</constant-name>
            <constant-value></constant-value>
          </constant>
        </global>
        
    <!-- ========== Default Language Form Definitions ===================== -->
       
          <formset>        
            <form name="loginActionForm">
              <field
                    property="userID"
                    depends="required">
                    <arg0 key="login.jsp.prompt.username"/>
                 </field>
              <field
                    property="password"
                    depends="required,mask">
                    <arg0 key="login.jsp.prompt.password"/>
                <var>
                    <var-name>mask</var-name>
                    <var-value>^[0-9a-zA-Z]*$</var-value>
                </var>
             </field>
            </form>
                </formset>
        
    </form-validation>3.   在浏览器端使用JavaScript进行验证
    <%@ page contentType="text/html; charset=UTF-8" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html:javascript formName="loginActionForm"/>
    <html:html>
    <head>
    <title><bean:message key="login.jsp.title"/></title>
    <html:base/>
    </head>
    <body>
    <html:form action="/loginAction.do" focus="userid" onsubmit="return validateLoginActionForm(this);" method="post">
      <div align="center">
        <table width="22%"  border="4">
          <tr>
            <td height="208"><div align="left">
              <table width="69%"  border="0">
                  <tr>
                    <td><font color="#000080"><font color="#000000"><bean:message key="login.jsp.prompt.username"/></font><strong> 
                      </strong></font></td>
                  </tr>
                  <tr>
                    <td><div align="left">
                      <html:text property="userID" maxlength="40"/>
                    </div></td>
                  </tr>
                  <tr>
                    <td height="18"><font color="#000080"><font color="#000000"><bean:message key="login.jsp.prompt.password"/><strong> 
                      </strong></font></font>&nbsp;</td>
                  </tr>
                  <tr>
                    <td><div align="center">
                        <html:password property="password" maxlength="10"/>
                    </div></td>
                  </tr>
                      </table>
              <table width="69%"  border="0">
                <tr>
                  <td height="38"><div align="right">
                      <html:submit><bean:message key="login.jsp.prompt.submit"/></html:submit>
                  </div></td>
                  <td><html:button property="close" onclick="window.close()"><bean:message key="login.jsp.prompt.close"/></html:button></td>
                </tr>
              </table>
        
            </div></td>    </table>
      </div> </html:form></body>
    </html:html>(http://blog.csdn.net/arqui/archive/2004/10/12/133717.aspx)