Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text box validator for minimum length

     <asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" ControlToValidate="NewPassword" 
ErrorMessage="New Password is required." ToolTip="New Password is required." ValidationGroup="ChangeUserPasswordValidationGroup">
 </asp:RequiredFieldValidator>

How can I validate the text box to enter a value which length should be more than 8 and must contain 1 number and 1 uppercase letter.

like image 386
John Avatar asked Sep 28 '11 10:09

John


2 Answers

<asp:RegularExpressionValidator ID="RegExp1" runat="server"    
ErrorMessage="Password length must be between 7 to 10 characters"
ControlToValidate="txtPassword"
ValidationExpression="^[a-zA-Z0-9'@&#.\s]{7,10}$" />
like image 59
WJHOO Avatar answered Oct 02 '22 11:10

WJHOO


In addition to your RequiredFieldValidator add a RegularExpressionValidator

For the regex pattern you can use this pattern:

^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$

Must be at least 8 characters Must contain at least one one lower case letter, one upper case letter, one digit and one special character Valid special characters are - @#$%^&+=

Technically you could use just the Regex validator but using multiples allows you to have different errors messages depending on a missing vs. simply incorrect password.

like image 37
The Evil Greebo Avatar answered Oct 02 '22 12:10

The Evil Greebo