Saturday, April 11, 2009

Validation for creditcard no

here i have post he regex for credit card number which has totally 16 digit

after every 4 digit it has "-" or not contain.


^(\d{4}-){3}\d{4}$|^(\d{4} ){3}\d{4}$|^\d{16}$

ex"

< %@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" % >
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

< html xmlns="http://www.w3.org/1999/xhtml" >

< head runat="server" >
< title> < /title >

< /head >

< body >

< form id="form1" runat="server" >

< div >

< asp:TextBox ID="TextBox1" runat="server" CausesValidation="True" > < /asp:TextBox >

< /div >
< asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"

ControlToValidate="TextBox1" ErrorMessage="your error message"

ValidationExpression="^(\d{4}-){3}\d{4}$|^(\d{4} ){3}\d{4}$|^\d{16}$" >< /asp:RegularExpressionValidator >
< /form >

< /body >

< /html >

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home