Give validation to textbox that accepts min 6 charecters and max 12 charecters in Asp.net


For that add textbox control with the property MaxLength=12 and add RegularExpressionValidator with RegularExpression.

<asp:TextBox ID="TxtName" runat="server" MaxLength="12" Width="200px"></asp:TextBox>

<br />
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1" 
ControlToValidate="TxtName"                                
ValidationExpression="(?=^.{6,12}$)(?=.*\d)(?=.*\W+)(?![.\n]).*$"
runat="server"
Text="Password must have minimum 6 characters & maximum 12 characters"></asp:RegularExpressionValidator>




0 comments:

Post a Comment