Get date of last day of current month for special processing like for credit card expiration dates

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.)

No Javascript libraries like JQuery is required!

Aaron Belchamber has written 243 articles

Leave a Reply

Your email address will not be published. Required fields are marked *