Skip to content

Instantly share code, notes, and snippets.

@isocroft
Last active April 11, 2024 23:55
Show Gist options
  • Save isocroft/072ea5e1f4d0d52eb034e7a6c93b5b76 to your computer and use it in GitHub Desktop.
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}$/
@isocroft
Copy link
Author

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

Maybe i can help

@immatobi
Copy link

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

@isocroft
Copy link
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. So that helped too.

@immatobi
Copy link

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

@isocroft
Copy link
Author

isocroft commented Apr 11, 2024

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