Credit Card Validation using Regular expression


Visa: ^4[0-9]{12}(?:[0-9]{3})?$  - Visa card will have 16 digits. Always starts with 4.

MasterCard:  ^5[1-5][0-9]{14}$ -  Master Card will have 16 digits. Always starts with 51 through 55.

American Express: ^3[47][0-9]{13}$  -   American Express will have 15 digits. Always starts with 34 or 37.



Diners Club: ^3(?:0[0-5]|[68][0-9])[0-9]{11}$

Discover: ^6(?:011|5[0-9]{2})[0-9]{12}$

JCB: ^(?:2131|1800|35\d{3})\d{11}$

For All:

^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$.

1 comments:

Unknown said...

Good information.......

Post a Comment

Vikram Chandra Theme by BloggerThemes & NewWPThemes Sponsored by iBlogtoBlog