You can create your own custom validation method using the addMethod
function. Say you wanted to validate "dd/mm/yyyy":
$.validator.addMethod(
"australianDate",
function(value, element) {
// put your own logic here, this is just a (crappy) example
return value.match(/^dd?/dd?/dddd$/);
},
"Please enter a date in the format dd/mm/yyyy."
);
And then on your form add:
$('#myForm')
.validate({
rules : {
myDate : {
australianDate : true
}
}
})
;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…