Last active
August 26, 2020 13:06
-
-
Save gokhangirgin/d4d004f483f4eab21111 to your computer and use it in GitHub Desktop.
Credit Card Expiry Date Regex Validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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