<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.
<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}$" />
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With