Title |
Test
Find
Pattern Title
|
Expression |
^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$ |
Description |
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. |
Matches |
6011-1111-1111-1111 | 5423-1111-1111-1111 | 341111111111111 |
Non-Matches |
4111-111-111-111 | 3411-1111-1111-111 | Visa |
Author |
Rating:
Steven Smith
|
Source |
|
Your Rating |
|
Title: Needs outer parens to avoid false positives
Name: Ralph Dosser
Date: 12/18/2008 12:59:19 PM
Comment:
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
Comment:
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
Comment:
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
Comment:
6011123412341234567890abcdefghijklmnopqrstuvwxyz