Solved

Checking Credit Card number is valid

Posted on 2011-09-20
2
455 Views
Last Modified: 2012-05-12
I need to check whether is credit card number is a valid format for the type of credit card that is giving to me. I am passing the number to other place that will do the actual check.  I had found this
for each card when I tested with actual number for the particular type for card I got errors. Am I missing something in the regular expression?

This is be coded in VBNET on the back end.

  Case "AX"
                    RegEx = New System.Text.RegularExpressions.Regex("3[4,7]\d{13}")
                Case "DS"
                    RegEx = New System.Text.RegularExpressions.Regex("6011-?\d{4}-?\d{4}-?\d{4}")
                Case "MC"
                    RegEx = New System.Text.RegularExpressions.Regex("5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}")
                Case "VA"
                    RegEx = New System.Text.RegularExpressions.Regex("4\d{3}-?\d{4}-?\d{4}-?\d{4}")


           
0
Comment
Question by:kw66722
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
binaryevo earned 500 total points
ID: 36569826
Try the following regex for the different card types:

Amex - ^3[47][0-9]{13}$
Discover - ^6(?:011|5[0-9]{2})[0-9]{12}$
Mastercard - ^5[1-5][0-9]{14}$
Visa - ^4[0-9]{12}(?:[0-9]{3})?$
0
 
LVL 1

Author Closing Comment

by:kw66722
ID: 36570637
worked like a charm thanks.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question