Here's a regular expression to validate the credit card expiry date in the format MM/YY or MM/YYYY:
index.tsx539 chars19 lines
The regular expression ^(0[1-9]|1[0-2])\/(2[1-9]|[3-9][0-9])$
matches strings that start with either 01-12 followed by a forward slash /
, and then followed by 21-99 or 3-9 plus any single digit.
The validateExpiryDate
function also checks whether the expiry year is between the current year and 2099, and returns a boolean value indicating whether the date is valid.
gistlibby LogSnag