RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Credit Card: Visa + MC
Expression
^(5[1-5]\d{2})\d{12}|(4\d{3})(\d{12}|\d{9})$
Description
A simple regex to check for only Visa and MasterCard with no dashes or spaces. Visa starts with a 4 and is 13 or 16 digits long, MasterCard starts with a 51 through 55 and is 16 digits long. I noticed that some of the other formulas don't account for Visa being valid with only 13 digits. I used this for a PayPal processor (which doesn't allow dashes or spaces) and modified it from others on this site. Enjoy.
Matches
5555555555554444 | 5105105105105100 | 4012888888881881 | 4222222222222
Non-Matches
123412341234 | 4222-2222-2222-2222 | visa | 41231234123412345
Author Rating: Not yet rated. Dan Partain
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: 5555555555554444
Name: Dann partain
Date: 12/1/2015 8:40:56 AM
Comment:
NO COMEMET


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials