- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
Matches major credit cards including: Visa (length 16, prefix 4), Mastercard (length 16, prefix 51-55), Discover (length 16, prefix 6011), American Express (length 15, prefix 34 or 37). All 16 digit formats accept optional hyphens (-) between each group of four digits.
6011-1111-1111-1111 | 5423-1111-1111-1111 | 341111111111111
4111-111-111-111 | 3411-1111-1111-111 | Visa
Author Rating: The rating for this expression. Steven Smith
Your Rating
Bad Good

Enter New 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: Needs outer parens to avoid false positives
Name: Ralph Dosser
Date: 12/18/2008 12:59:19 PM
The entire thing is OR'd between the 16 and 15 digit possibilities, but the begin string ^ only goes with the 16 digits and the end string $ only goes with the 15 digits. This goes away if you encase the whole thing in parens thus: ^(((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13})$ Without those, you can put any prefix you want on a valid 15-digit combo or any suffix you want on a valid 16-digit combo and it will read positive.

Title: Mr.
Name: Prashant
Date: 4/1/2005 3:15:26 PM
Hi, Excellent Code!!!! I'll appreciate if u can help me wit follwoing reg exprn: * String should contain 7 numbers or 7 digits consisting of 1 letter & 6 numbers in varying order, no spaces. For this one, reg expn = (\\d{7})|((\\d*[a-zA-Z]\\d*){7}) But this is also not working...... Please help!!!!! * String should contain 9 numbers or 8 alphanumeric characters i.e. 8 numbers/letters or 13 numbers This one looks really simple, but still (\\d{9})|(\\w{8})|(\\d{13}) is not working.....Please helpppp

Title: spaces
Name: anon
Date: 5/20/2004 2:38:24 PM
does not allow spaces... but this minor variation will: ^((4\d{3})|(5[1-5]\d{2})|(6011))[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}|3[4,7]\d{13}$

Title: false positive
Name: rob eberhardt
Date: 1/20/2004 6:37:02 AM

Copyright © 2001-2024, | ASP.NET Tutorials