custom validation method
custom validation method
Hi all,
Im sure this is simple, but man its frustrating! I need to add a custom validation method for a date in the following format MM/YYYY the slash between the 2 digit month and 4 digit year is giving me some issues. This will be used with jquery.validation.js Has anyone had this issue or know how to solve it?
This isn't working as I want it still expects a day
$.validator.addMethod("dateCC",function(value, element) {
var check = false;
var re = /^\d{1,2}\/\d{4}$/;
if( re.test(value)){
var adata = value.split('/');
var mm = parseInt(adata[1],10);
var aaaa = parseInt(adata[2],10);
var xdata = new Date(aaaa,mm-1);
if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) )
check = true;
else
check = false;
} else
check = false;
return this.optional(element) || check;
},
"Please enter a correct date in MM/YYYY format"
);
thanks,