Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Checking Credit Card number is valid

Posted on 2011-09-20
2
Medium Priority
?
463 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses

972 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