0
我需要在我的文本框中排除單引號和雙引號的用法。如果用戶輸入文字與我需要顯示錯誤。我如何與jquery.validate做如何僅允許使用jquery.validate的文本框中的文本?
我需要在我的文本框中排除單引號和雙引號的用法。如果用戶輸入文字與我需要顯示錯誤。我如何與jquery.validate做如何僅允許使用jquery.validate的文本框中的文本?
$('#elm').validate(
{
valid: function(inputValue){
return !inputValue.match(/['"]+/);
}
});
使用正則表達式像^ [A-ZA-Z] 這將接受A-Z和A-Z中的字符。
這裏是代碼: 添加正則表達式的方法。
$.validator.addMethod("regex",function(value,element,regexp){
var re= new RegExp(regexp);
return this.optional(element) || re.test(value);
},"Only Characters from A-z");
然後你需要在該字段上添加一條規則。
rules:{
username:{
required:true,
regex:"^[a-zA-Z]+$" //Only Characters
}
},
messages:{
username:{
required:"Mandatory"
}
},
完蛋了..
我不知道如何使用它。請解釋一下。 – 2010-12-13 04:49:21
如果*有*有引號,它們不會匹配嗎? – alex 2010-12-13 04:50:59
引用這個插件:http://plugins.jquery.com/project/jqueryvalidate – 2010-12-13 04:51:49