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

	<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;
 }
提示不能为空:

dojo小例子(8)ValidationTextBox密码校验,两次输入一致性校验_第1张图片

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


两次输入不一致,提示:

dojo小例子(8)ValidationTextBox密码校验,两次输入一致性校验_第2张图片

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

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


你可能感兴趣的:(dojo)