You are not Logged in
Would you like to Login or Register

Today is: Wednesday, 03 December, 2008
Check this months hot topics

Credit Card Matching

The following patterns are useful for first stage of credit card validation for Visa and Mastercards.

Visa pattern:

 /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/

Mastercard pattern:

 /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/

This does not prove the number is valid but that it contains the correct content so it is a handy and light weight first stage validation.

To fully validate you must calculate a check digit. If this check digit is divisible by 10 then you have validated the Visa or Mastercard number!

kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Mark Page Skype
Author : Mark Page
Published : Monday, 18 June, 2007

Mark is trying not to drink too much 'cool aid' at the moment. All the more for everyone else!

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views

More Publications

URL Regular Expression
Paul Hayman - 26/7/2006
IsGuid() (Regular Expression Guid Match)
Paul Hayman - 14/6/2006
IP Address regular expression
Paul Hayman - 4/8/2006
ISBN Number regular expression
Paul Hayman - 4/8/2006
Email Address Regular Expression
Paul Hayman - 26/7/2006