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

前端之家收集整理的这篇文章主要介绍了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,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,validator:function(){return this.value == dijit.byId('password1').value},invalidMessage:'两次输入的密码不相同!'" /></p>

猜你在找的Dojo相关文章