Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gokhangirgin/d4d004f483f4eab21111 to your computer and use it in GitHub Desktop.
Save gokhangirgin/d4d004f483f4eab21111 to your computer and use it in GitHub Desktop.
Credit Card Expiry Date Regex Validator
<!--
Allow these formats
- m/YY
- mm/YY
- m/YYYY
- mm/YYYY
- month 1-12
- year > 14 && year < 2099
http://jsfiddle.net/GhxKx/4/
-->
<ul id="testResults"></ul>
var testCases = ["1/18","09/22","99/99","asd","a/bb","0/10","05/13","3/96","as/ds", "00/19","10/990","09/2017"];
var pattern = new RegExp("^(0[1-9]|1[0-2]|[1-9])\/(1[4-9]|[2-9][0-9]|20[1-9][1-9])$");
var result;
for(var i = 0; i < testCases.length; i++)
{
result = pattern.test(testCases[i]) ? "<span style='color:green'>Pass : " + testCases[i] + '</span>'
: "<span style='color:red'>Fails : " + testCases[i] + '</span>';
document.getElementById("testResults").innerHTML += "<li>"+ result + "</li>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment