关于validator的问题

hill123 04-12-09

  我在Validator中使用javascript作客户端验证时,遇到一个问题:
在JSP页面中有两个文本框:两个都是text。运行的时候对两个文本框的数据作requerid,mask,minlength的验证。一切正常。
但是把其中一个的类型改为password后,发现对其作minlength验证时无效。
  请帮助解决一下。

hill123
2004-12-09 03:13

程序运行后,生成的javascript的代码:
<script type="text/javascript" language="Javascript1.1">

<!-- Begin
var bCancel = false;
function validateLogonForm(form) {
if (bCancel)
return true;
else
return validateRequired(form) && validateMask(form) && validateMinLength(form);
}
function required () {
this.aa = new Array("logonid", "帐号 必须填写.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
this.ab = new Array("logonpw", "密码 必须填写.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
}
function mask () {
this.aa = new Array("logonid", "帐号 格式错误.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
this.ab = new Array("logonpw", "密码 格式错误.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
}
function minlength () {
this.aa = new Array("logonid", "帐号 不能小于 4 个字符.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
this.ab = new Array("logonpw", "密码 不能小于 4 个字符.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
}
//End -->
</script>

hill123
2004-12-09 03:16

var bCancel = false;

function validateLogonForm(form) {
if (bCancel)
return true;
else
return validateRequired(form) && validateMask(form) && validateMinLength(form);
}

function required () {
this.aa = new Array("logonid", "帐号 必须填写.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
this.ab = new Array("logonpw", "密码 必须填写.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
}

function mask () {
this.aa = new Array("logonid", "帐号 格式错误.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
this.ab = new Array("logonpw", "密码 格式错误.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
}

function minlength () {
this.aa = new Array("logonid", "帐号 不能小于 4 个字符.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
this.ab = new Array("logonpw", "密码 不能小于 4 个字符.", new Function ("varName", "this.mask=/^[a-zA-Z0-9]*$/; this.minlength='4'; return this[varName];"));
}

hill123
2004-12-09 03:18

JSP代码如下:
< body>
< html:javascript formName="logonForm" dynamicJavascript="true" staticJavascript="false"/>
< script language="javascript1.1" src="staticJavascript.jsp"></script>
< html:form action="/logonAction.do" method="post" onsubmit="return validateLogonForm(this);">
< table>
< tr>
< td align="right">
< bean:message key="logonForm.logonid"/>
< /td>
< td>
< html:text property="logonid" maxlength="12" size="12"/>
< /td>
< /tr>
< tr>
< td align="right">
< bean:message key="logonForm.logonpw"/>
< /td>
< td>
< html:password property="logonpw" maxlength="12" size="12"/>
< /td>
< /tr>
< tr>
< td align="center" colspan="2">
< html:submit><bean:message key="logonForm.submit"/></html:submit>
< html:reset><bean:message key="logonForm.reset"/></html:reset>
< /td>
< /tr>
< /table>
< /html:form>
< /body>

hill123
2004-12-09 03:20

validation.xml的代码如下:
< form-validation>
< global>
< constant>
< constant-name>logonid< /constant-name>
< constant-value>^[a-zA-Z0-9]*$< /constant-value>
< /constant>
< constant>
< constant-name>logonpw< /constant-name>
< constant-value>^[a-zA-Z0-9]*$< /constant-value>
< /constant>
< /global>
< formset>
< form name="logonForm">
< field property="logonid" depends="required,mask,minlength">
< arg0 key="logonForm.logonid"/>
< arg1 name="minlength" key="${var:minlength}" resource="false"/>
< var>
< var-name>mask</var-name>
< var-value>${logonid}< /var-value>
< /var>
< var>
< var-name>minlength< /var-name>
< var-value>4</var-value>
< /var>
< /field>
< field property="logonpw" depends="required,mask,minlength">
< arg0 key="logonForm.logonpw"/>
< arg1 name="minlength" key="${var:minlength}" resource="false"/>
< var>
< var-name>mask< /var-name>
< var-value>${logonpw}< /var-value>
< /var>
< var>
< var-name>minlength< /var-name>
< var-value>4< /var-value>
< /var>
< /field>
< /form>
< /formset>
< /form-validation>