[jQuery] validate date regexp
Hi, I'm using the jQuery validation plugin + masked Input 1.2.2 and
both works very well.
I'd like to add a validation function for dates with the format dd/mm/
yyyy
I took the regexp from http://bassistance.de/jquery-plugins/jquery-plugin-validation/
specifically from Marco Antonio's post but if figured out that it
doesn't work well for all leap years, for example it works for
29/02/2004 but not for 29/02/2000
Is there any way someone can tweak the regexp a little bit?
Thanks
jQuery.validator.addMethod(
"date",
function(value, element) {
var check = false;
var re = /^(?:(?:(?:0?[1-9]|1\d|2[0-8])\/(?:0?[1-9]|1[0-2]))\/(?:(?:1
[6-9]|[2-9]\d)\d{2}))$|^(?:(?:(?:31\/0?[13578]|1[02])|(?:(?:29|30)\/(?:
0?[1,3-9]|1[0-2])))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:29\/0?2\/(?:(?:
(?:1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26]))))$/
if( re.test(value)){
check = true;
}
return this.optional(element) || check;
},
"Please enter a correct date"
);