Soldato
- Joined
- 27 Dec 2005
- Posts
- 17,316
- Location
- Bristol
I've got an input field for a date that is NOT required, but if filled must be in the correct format.
I've got (with irrelevant bits snipped out):
However submitting when it's blank brings up the error. I'm useless with Regex so how do I add an 'OR blank' to the ukDate function?
I've got (with irrelevant bits snipped out):
Code:
$.validator.addMethod("ukDate",
function(value, element) {
return value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/);
},
"Please enter a date in the format DD/MM/YYYY."
);
$(document).ready(function() {
var validator = $("#form").validate({
rules: {
ukdate: {
required:false,
ukDate:true,
},
},
});
});
However submitting when it's blank brings up the error. I'm useless with Regex so how do I add an 'OR blank' to the ukDate function?