Solved

Checking Credit Card number is valid

Posted on 2011-09-20
2
441 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now