Created
May 30, 2019 19:59
-
-
Save rofc/a999529c0d2fca3c8408c5910a8dc26b to your computer and use it in GitHub Desktop.
Credit Card Regex
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
# Based on https://baymard.com/checkout-usability/credit-card-patterns | |
ALL TOGETHER | |
============ | |
(?:4[0-9]{3}(?:[\ -]?[0-9]{4}){3})|(?:4(?:026|405|508|844|913|917)[-\ ]?[0-9]{4}|4175[-\ ]?00[0-9]{2})(?:[-\ ]?[0-9]{4}){2}|(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)(?:[-\ ]?[0-9]{4}){3}|3[47][0-9]{2}[-\ ]?[0-9]{6}[-\ ]?[0-9]{5}|62[0-9]{2}[-\ ]?(?:[-\ ]?[0-9]{4}){3}|62[0-9]{4}[-\ ]?[0-9]{13}|(?:5[0678][0-9]{2}|6[0-9]{3})[-\ ]?[0-9]{4}[-\ ]?[0-9]{5}|(?:5[0678][0-9]{2}|6[0-9]{3})[-\ ]?[0-9]{6}[-\ ]?[0-9]{5}|(?:5[0678][0-9]{2}|6[0-9]{3})(?:[-\ ]?[0-9]{4}){3}|(?:5[0678][0-9]{2}|6[0-9]{3})(?:[-\ ]?[0-9]{4}){3}[-\ ]?[0-9]{3}|(?:30[0123459][0-9]|3[689][0-9]{2})[-\ ]?[0-9]{6}[-\ ]?[0-9]{4}|5[45][0-9]{2}(?:[-\ ]?[0-9]{4}){3}|(?:6011[-\ ]?[0-9]{4}|6221[-\ ]?2[6-9][0-9]{2}|6221[-\ ]?[3-9][0-9]{3}|622[2-8][-\ ]?[0-9]{4}|6229[-\ ]?[01][0-9]{3}|6229[-\ ]?2[0-5][0-9]{2})(?:[-\ ]?[0-9]{4}){2}|(?:352[89]|35[3-7][0-9]|358[0-9])(?:[-\ ]?[0-9]{4}){3}|1[0-9]{3}[-\ ]?[0-9]{5}[-\ ]?[0-9]{6}|5019(?:[-\ ]?[0-9]{4}){3}|636[0-9](?:[-\ ]?[0-9]{4}){3} | |
ONE BY ONE | |
========== | |
VISA | |
(?:4[0-9]{3}(?:[\ -]?[0-9]{4}){3}) | |
VISA ELECTRON | |
(?:4(?:026|405|508|844|913|917)[-\ ]?[0-9]{4}|4175[-\ ]?00[0-9]{2})(?:[-\ ]?[0-9]{4}){2} | |
AMERICAN EXPRESS | |
3[47][0-9]{2}[-\ ]?[0-9]{6}[-\ ]?[0-9]{5} | |
CHINA UNIONPAY | |
62[0-9]{2}[-\ ]?(?:[-\ ]?[0-9]{4}){3} | |
62[0-9]{4}[-\ ]?[0-9]{13} | |
MASTERCARD | |
(?:5[1-5][0-9]{2}|222[1-9]|22[3-9][0-9]|2[3-6][0-9]{2}|27[01][0-9]|2720)(?:[-\ ]?[0-9]{4}){3} | |
MAESTRO | |
(?:5[0678][0-9]{2}|6[0-9]{3})[-\ ]?[0-9]{4}[-\ ]?[0-9]{5} | |
(?:5[0678][0-9]{2}|6[0-9]{3})[-\ ]?[0-9]{6}[-\ ]?[0-9]{5} | |
(?:5[0678][0-9]{2}|6[0-9]{3})(?:[-\ ]?[0-9]{4}){3} | |
(?:5[0678][0-9]{2}|6[0-9]{3})(?:[-\ ]?[0-9]{4}){3}[-\ ]?[0-9]{3} | |
DINERS | |
(?:30[0123459][0-9]|3[689][0-9]{2})[-\ ]?[0-9]{6}[-\ ]?[0-9]{4} | |
5[45][0-9]{2}(?:[-\ ]?[0-9]{4}){3} | |
DISCOVER | |
(?:6011[-\ ]?[0-9]{4}|6221[-\ ]?2[6-9][0-9]{2}|6221[-\ ]?[3-9][0-9]{3}|622[2-8][-\ ]?[0-9]{4}|6229[-\ ]?[01][0-9]{3}|6229[-\ ]?2[0-5][0-9]{2})(?:[-\ ]?[0-9]{4}){2} | |
JCB | |
(?:352[89]|35[3-7][0-9]|358[0-9])(?:[-\ ]?[0-9]{4}){3} | |
UATP | |
1[0-9]{3}[-\ ]?[0-9]{5}[-\ ]?[0-9]{6} | |
DANKORT | |
5019(?:[-\ ]?[0-9]{4}){3} | |
INTERPAYMENT | |
636[0-9](?:[-\ ]?[0-9]{4}){3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you