Loading ...

Credit card validation through regular expression validator in asp.net | CodeAsp.Net

Credit card validation through regular expression validator in asp.net

 /5
0 (0votes)

Couple of month ago I had worked on e-commerce site, where I have to validate the credit card number.

I have described some dummy credit card number by which you can test .

1. Master Card : 5431-1111-1111-1111

  master card have 16 numbers starting with 5.

2.Visa : 4111-1111-1111-1111 or 4111-1111-1111-1

 Visa have 13 or 16 numbers starting with 4

3: American Express : 341-1111-1111-1111 or 371-1111-1111-1111

  American Express have 15 numbers starting with 34 or 37

For validating the card number we have to write a regular expression for validation expresion property of RegularExpressionValidator:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="textbox1"

ValidationExpression="^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{13}$"

ErrorMessage="Please enter valid Name on card" > *</asp:RegularExpressionValidator>

 

Hope this will help....

Comments (4)

   
prasu222
GOOD IT'S WORKING,,,,DUDE
4/21/2009
 · 
by
   
prasu222
GOOD IT'S WORKING,,,,DUDE
4/21/2009
 · 
by
   
Nagesh
Nagesh
hi friend i tried ur code for credit card validations its nt work for American Express card
please let me knw
and mail me if u can.
thank you
nagu
nagesh212@gmail.com
11/26/2009
 · 
by
   
vinay_jss
Hi Nagesh,
You can try the following
^(?: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})$
11/26/2009
 · 
by

Top Posts