1
如何使用addMethod()方法編寫新方法?我想驗證一個電話號碼,它以0開始,它的長度是10。我試過到目前爲止:添加方法jQuery驗證
function cell(element, value){
if (!/^[0]\d{9}$/.test(element).val()) {
return false;
}
else {
return true;
}
}
$.validator.addMethod("cell", cell, "This phone number is incorrect");
和:
$("#signupForm").validate({
rules: {
cell: {
required: true,
digits: true,
cell: true
}
}
})
而在消息我應該在寫'cell'的消息給?謝謝!
[自定義方法與jQuery驗證插件]的可能重複(http://stackoverflow.com/questions/15589152/custom-method-with-jquery-validation-plugin) –