当前位置 : 主页 > 网页制作 > Dojo >

dojo小例子(8)ValidationTextBox密码校验,两次输入一致性校验

来源:互联网 收集:自由互联 发布时间:2021-06-15
pPassword: input type="password" name="password1" id="password1" data-dojo-type="dijit/form/ValidationTextBox" data-dojo-props="required:true, intermediateChanges:false, regExp:'[a-zA-Z][a-zA-Z0-9_]{5,15}', invalidMessage:'以字母开头,字
	<p>Password: <input type="password"
    name="password1"
    id="password1"
    data-dojo-type="dijit/form/ValidationTextBox"
    data-dojo-props="required:true, intermediateChanges:false, 
    	regExp:'[a-zA-Z][a-zA-Z0-9_]{5,15}', 
    	invalidMessage:'以字母开头,字母数字下划线组合,6-16字符'" /></p>

	<p>Confirm: <input type="password"
    name="password2"
    id="password2"
    data-dojo-type="dijit/form/ValidationTextBox"
    data-dojo-props="required:true, intermediateChanges:false, 
    	validator:confirmPassword, 
    	constraints:{'other': 'password1'}, 
    	invalidMessage:'两次输入的密码不相同!'" /></p>
 require(['dojo/parser', 'dojo/domReady!'],
		  function(parser){
		    parser.parse();
 });
 function confirmPassword(value, constraints)
 {
     var isValid = false;
     if(constraints && constraints.other)  {
     	var otherInput =  dijit.byId(constraints.other);
     	if(otherInput) {
     		var otherValue = otherInput.value;
     		isValid = (value == otherValue);
     	}
     }
     return isValid;
 }
提示不能为空:

输入数字,会提示必须以字母开头:


两次输入不一致,提示:


后来发现有更简单的写法:

    <p>Confirm: <input type="password"
    name="password2"
    id="password2"
    data-dojo-type="dijit/form/ValidationTextBox"
    data-dojo-props="required:true, intermediateChanges:false, 
    	validator:function(){return this.value == dijit.byId('password1').value}, 
    	invalidMessage:'两次输入的密码不相同!'" /></p>
网友评论