jquery验证器添加新方法不会';行不通
我不明白那种工作方法。如果我输入了错误的号码,我不会收到任何消息 我的main.jsjquery验证器添加新方法不会';行不通,jquery,jquery-validate,Jquery,Jquery Validate,我不明白那种工作方法。如果我输入了错误的号码,我不会收到任何消息 我的main.js $.validator.setDefaults({ errorClass: 'form_error', errorElement: 'div' }); $.validator.addMethod("dniCheck", function(value, element){ var valor = false; if(/^([0-9]{8})*[a-zA-Z]+$/.test(valu
$.validator.setDefaults({
errorClass: 'form_error',
errorElement: 'div'
});
$.validator.addMethod("dniCheck", function(value, element){
var valor = false;
if(/^([0-9]{8})*[a-zA-Z]+$/.test(value)){
var numero = value.substr(0, value.length-1);
numero = numero % 23;
var let = 'TRWAGMYFPDXBNJZSQVHLCKET';
letra = let.substring(numero,numero+1);
if(letra===let) valor = true;
}
valor = this.optional(element);
console.log(valor);
return valor;
},"DNI no válido");
$("#form_participante").validate({
rules:{
nie:{
dniCheck: true
}
},
messages:{
nie:{
dniCheck:"Introduce el dni correcto"
}
}
});
我的表格
<form id="form_participante" action="{{ urlFor('AltaParticipante') }}" method="POST" class="form-horizontal">
<fieldset>
<legend>Alta nuevo participante</legend>
<div class="form-group">
<label class="col-md-4 control-label" for="nieP">Nie participante</label>
<div class="col-md-5">
<input id="nieP" name="nieP" placeholder="Nie del participante..." class="form-control input-md" type="text" />
</div>
</div>
...
</form>
Alta nuevo participante
Nie参与者
...
在另一种形式中,我很好地验证了字段
我没有得到任何错误
github中的repository=>脚本的第一行遗漏了一个
$
?字段的名称是nieP
,但您在.validate()
方法中将其拼写为nie
。name
属性必须匹配
$("#form_participante").validate({
rules: {
nie: { // <- MUST match the NAME attribute
dniCheck: true
}
}, .....
$(“#表单#参与者”)。验证({
规则:{
nie:{/nie
不匹配nieP