Skip to content

Instantly share code, notes, and snippets.

@isocroft
Last active November 17, 2025 18:42
Show Gist options
  • Select an option

  • Save isocroft/072ea5e1f4d0d52eb034e7a6c93b5b76 to your computer and use it in GitHub Desktop.

Select an option

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
/*
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}$/
@ManeendraNath

Copy link
Copy Markdown

Regex for Rupay Debit and Credit Card is not available in the list.

@isocroft

Copy link
Copy Markdown
Author

Hello @ManeendraNath , can you get me 6 sample Rupay Card numbers ?

Maybe i can help

@immatobi

Copy link
Copy Markdown

Hey @isocroft Thanks for this. Any chance you can give a little hint on how you came up with these regexes?

@isocroft

isocroft commented Apr 11, 2024

Copy link
Copy Markdown
Author

Hello @immatobi , You're welcome.

I got the initial details from here and then i did additional research to setup the rest (e.g. verve, hipercard).

Fortunately, I know how to breakdown and craft regular expressions from scratch. So that helped too.

@immatobi

Copy link
Copy Markdown

Thanks for this. I'll definitely check it out and add more to the cards in my project.

@isocroft

isocroft commented Apr 11, 2024

Copy link
Copy Markdown
Author

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.

@isocroft

isocroft commented Mar 3, 2025

Copy link
Copy Markdown
Author

Implemented in python πŸ‘‡πŸΎπŸ‘‡πŸΎπŸ‘‡πŸΎ

"""
       Modified with more card regexs
       
       See initial source: https://www.regular-expressions.info/creditcard.html
"""
visa = re.compile(r"^4[0-9]{12}(?:[0-9]{3,4})")
visa_local = re.compile(r"^4[19658][7684][0785][04278][128579](?:[0-9]{10})")
mastercard = re.compile(r"^(?: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}")
mastercard_local = re.compile(r"^(?:5[13]99|55[35][19]|514[36])(?:11|4[10]|23|83|88)(?:[0-9]{10})")
verve = re.compile(r"^(?:50[067][180]|6500)(?:[0-9]{15})")
american_express = re.compile(r"^3[47](?:[0-9]{13})")
diners_club = re.compile(r"^3(?:0[0-5]|[68][0-9])[0-9]{11}")
maestro = re.compile(r"^(5899|5018|5020|5038|6304|6703|6708|6759|676[1-3])[06][19](?:[0-9]{10})")
discover = re.compile(r"^6(?:011|4[4-9]3|222|5[0-9]{2})[0-9]{12}")
laser = re.compile(r"^(6706|6771|6709)[0-9]{11,15}")
hipercard = re.compile(r"^(384100|384140|384160|606282|637095|637568|60(?!11))")
jcb = re.compile(r"^(?:2131|1800|35\d{3})\d{11}")

@immatobi

Copy link
Copy Markdown

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.

Yes, got it

@immatobi

Copy link
Copy Markdown

Implemented in python πŸ‘‡πŸΎπŸ‘‡πŸΎπŸ‘‡πŸΎ

"""
       Modified with more card regexs
       
       See initial source: https://www.regular-expressions.info/creditcard.html
"""
visa = re.compile(r"^4[0-9]{12}(?:[0-9]{3,4})")
visa_local = re.compile(r"^4[19658][7684][0785][04278][128579](?:[0-9]{10})")
mastercard = re.compile(r"^(?: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}")
mastercard_local = re.compile(r"^(?:5[13]99|55[35][19]|514[36])(?:11|4[10]|23|83|88)(?:[0-9]{10})")
verve = re.compile(r"^(?:50[067][180]|6500)(?:[0-9]{15})")
american_express = re.compile(r"^3[47](?:[0-9]{13})")
diners_club = re.compile(r"^3(?:0[0-5]|[68][0-9])[0-9]{11}")
maestro = re.compile(r"^(5899|5018|5020|5038|6304|6703|6708|6759|676[1-3])[06][19](?:[0-9]{10})")
discover = re.compile(r"^6(?:011|4[4-9]3|222|5[0-9]{2})[0-9]{12}")
laser = re.compile(r"^(6706|6771|6709)[0-9]{11,15}")
hipercard = re.compile(r"^(384100|384140|384160|606282|637095|637568|60(?!11))")
jcb = re.compile(r"^(?:2131|1800|35\d{3})\d{11}")

Made a change here?

@isocroft

Copy link
Copy Markdown
Author

No @immatobi , i didn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment