我试图验证一个文本字段类型的密码,但是当我尝试编写密码时,验证不起作用。用于验证:minlength 6、maxlength 12、大写、小写和数字
HTML
<tr>
<td>Contraseña *</td>
<td>
<input type="password" name="password1" id="password1">
</td>
</tr>
JAVASCRIPT
$.validator.addMethod("password1", function (value, element) {
return this.optional(element) || /^(?=.*\d)(?=.*[a-zA-Z]).{6,12}$/i.test(value);
});
$("#frmDatos").validate({
errorContainer: contenedor,
errorLabelContainer: $("ol", contenedor),
wrapper: 'li',
meta: "validate",
rules: {
password1: {
required: true
}
},
messages: {
password1: "La contraseña no es válida"
},