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>