Solved

Checking Credit Card number is valid

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Compare site how does it work 4 71
Search by two fields at the same time using c# radio button 5 37
Registering DLL 5 43
Turn on intranet settings 1 36
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

947 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

19 Experts available now in Live!

Get 1:1 Help Now