I can’t seem to get this right, I can get it to catch a past date, but not return true on future date.I just need to validate my form’s Credit Card Expiration Date as being in the future, this isn’t working, any ideas? the date has to be in the format MM/YYYY with a “/” in between them.
$.validator.addMethod(
"FutureDate",
function(value, element) {
var startdatevalue = (.getMonth/.getYear);
return Date.parse(startdatevalue) < Date.parse($("#ExpirationDate").val());
},
"End Date should be greater than Start Date."
);
You’re not actually getting it to catch a past date. If you’re passing a date like this “11/2010” to your
Date.parse(), it is returningNaN(or Not a Number) which is the logical equivalent to returningfalse.Try doing this to see what I mean:
If you add a day number, it should work. Something like:
Of course, this example uses a hard coded date. If the values are stored as
11/2010, you could try something like this: