In case you ever need to manually validate those pesky multi-field credit card date fields, you know “Month” and “Year” and you want to make sure the expiration is never set prior to the current month for obvious reasons like the credit card would get declined, you need to have the browser client side figure out (or be given the value through PHP injection into your JS script) the last date of the last day of the current month so you can then calculate and compare the “Month” and “Year” fields to this date value.
Using Javascript’s Date object should be adequate for most browsers and IE 8 or greater (there’s a work around to accommodate older browsers, but is it really worth reaching people who are using IE7?! That’s a cost/benefit decision you and your marketing team will have to make.)
dt=new Date();
new Date(dt.getFullYear(), dt.getMonth() + 1, 0, 23, 59, 59)
No Javascript libraries like JQuery is required!
Like this:
Like Loading...