Last active
April 11, 2024 23:55
-
-
Save isocroft/072ea5e1f4d0d52eb034e7a6c93b5b76 to your computer and use it in GitHub Desktop.
This JavaScript file contains regex for all popular credit/debit card numbers: both for local (Nigerian) cards and international
This file contains 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
/* | |
Modified with more card regexs | |
See initial source: https://www.regular-expressions.info/creditcard.html | |
*/ | |
let visa = /^4[0-9]{12}(?:[0-9]{3,4})?$/ | |
let visa_local = /^4[19658][7684][0785][04278][128579](?:[0-9]{10})$/ | |
let 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]{12}$/ | |
let mastercard_local = /^(?:5[13]99|55[35][19]|514[36])(?:11|4[10]|23|83|88)(?:[0-9]{10})$/ | |
let verve = /^(?:50[067][180]|6500)(?:[0-9]{15})$/ | |
let american_exp = /^3[47](?:[0-9]{13})$/ | |
let diners_club = /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/ | |
let maestro = /^(5899|5018|5020|5038|6304|6703|6708|6759|676[1-3])[06][19](?:[0-9]{10})$/ | |
let discover = /^6(?:011|4[4-9]3|222|5[0-9]{2})[0-9]{12}$/ | |
let laser = /^(6706|6771|6709)[0-9]{11,15}$/ | |
let hipercard = /^(384100|384140|384160|606282|637095|637568|60(?!11))/ | |
let jcb = /^(?:2131|1800|35\d{3})\d{11}$/ | |
Thanks for this. I'll definitely check it out and add more to the cards in my project.
Sure thing @immatobi.
Remember mastercard_local
, visa_local
and verve
are for only Naira debit/credit cards.
mastercard
and visa
e.t.c are for foreign currency debit/credit cards.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @isocroft Thanks for this. Any chance you can give a little hint on how you came up with these regexes?