Click here to Skip to main content
15,745,574 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi i want code in regex or that match credit card with NUMBER+EXPIRE+CVV in one regex line what I done


credit card number MATCH


I need credit card match only if match like this

(!chk) beginning word (n) credit card number (M) month (y) year (X) cvv

!chk nnnnnnnnnnnnnnn mmyy xxx

!chk nnnnnnnnnnnnnnn mm|yy xxx

!chk nnnnnnnnnnnnnnn mm/yy xxx

!chk nnnnnnnnnnnnnnn mm\yy xxx

!chk nnnnnnnnnnnnnnn mmyyyy xxx

What I have tried:


     credit card number MATCH

Updated 25-Sep-19 11:06am

Using RegEx for Credit Cards is at best rudimentary; you are better off validating what you are actually working with

Credit Card numbers themselves are generally at least 16 digits long; the primary exception being American Express which uses 15 digits.

CVV numbers are 3 digits long for most; and again, American Express is the outlier with 4 digits.

Dates are 2x2 digits.

Now for validating....
Identify the card being presented-
It it a card that your business will accept?
Is it the correct length?
Does it pass the LUHN algorithm check.

CVV only needs to match the correct length; which depends on identifying the card type

Expiration date needs to be a valid month and date, AND it must be in the future
Share this answer
Credit card is simple 12 16 digits. <- sorry, not 12 but 16
MM is something like (0[1-9]|1[012]) - i.e 01-09 or 10-12
YY is 2 digits, but you may need to limit their range.
CVV is 3 digits
Share this answer
Member 14603662 25-Sep-19 10:56am    
so how can be merge regex in one line
Richard MacCutchan 25-Sep-19 11:45am    
"Put them together and what have you got?"

See RegExr: Learn, Build, & Test RegEx[^] where you can test it.
i want code in regex or that match credit card with NUMBER+EXPIRE+CVV in one regex line

What about putting the 3 parts together with a space in between?

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre -[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900