我只想在文本字段中包含用户输入的值.我正在使用"{0}"密钥,但它返回真假.小提琴
$.validator.addMethod("specialChar", function(value, element){
var patt = new RegExp(/[^A-z]/g);
return !patt.test(value)
},"{0} is not valid");
$('#myform').validate({
onfocusout:function(element){
this.element(element)
},
rules:{
username:{
required:true,
specialChar:true
}
},
messages:{
"username": {
required: "Please enter user name"
}
}
})
Run Code Online (Sandbox Code Playgroud)
您可以将值赋给this.value,然后使用返回字符串的字符串消息使用函数.在该函数内,您可以访问this.value
看看这个jsFiddle
$.validator.addMethod("specialChar", function(value, element){
this.val = value;
return false;
}, function() {
return 'not allowed ' + this.val;
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1004 次 |
| 最近记录: |