Reputation: 7571
I need to verify a credit card (dummy - i'm not doing any transaction in real). The conditions are
It has to be between 10 and 16 digits.
Start with a digit 3 or 4
Only digits are allowed i mean [0-9].
I tried it and mine was [3-4][0-9]{10-16}. But it seems to be not yielding results.
Thank you in anticipation
Upvotes: 1
Views: 2517
Reputation: 3748
You may want to determine if the credit card number does more than just meet the format of the RegEx by using some more aggressive validation.
You could use the Luhn algorithm to verify the number or even use further validation to tell you what company the credit card number belongs to.
Upvotes: 1
Reputation: 138017
Should be:
^[34][0-9]{9,15}$
[34]
one of the characters. [3-4]
is the same.{9,15}
is the proper syntax. Note that [34]
is the first digit, so you need to subtract one.Some Examples: http://www.rubular.com/r/q61cPPYW7E
Upvotes: 12