发帖    主题    评论    推荐    标签    作者    订阅    查搜    注册   登陆   关注
 
面向对象 设计模式 领域驱动设计 企业架构 框架 开发教程 微服务 CQRS 扩展性 并发编程 事件溯源 分布式 SOA

关于validator的问题

2004-12-09 03:13
赞助商链接

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

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>

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];"));
}

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>

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>

赞助商链接

赞助商链接

返回顶部

移动版 关于本站 使用帮助 联系反馈 最佳分辨率1366x768
OpenSource JIVEJDON Powered by JdonFramework Code © 2002-20 jdon.com