Regular Expression to Match Credit Card Expiration Date

I needed to validate a credit card expiration date and this is the regular expression I cobbled together by looking at various sources.

/^(0[1-9]|1[0-2])\/|\-?([0-9]{4}|[0-9]{2})$/

It’s nearly identical to a regex in this Stack Overflow discussion. All I did was make it work for 01-2020, as well as, 01/2020.

Share Button