I'm new on Asp. I have a problem to using regex for checking password input. Here the regex
<asp:RegularExpressionValidator ID="Regex1" runat="server"
ErrorMessage="Password must contain: Minimum 8 characters atleast 1 UpperCase Alphabet, 1 LowerCase Alphabet, 1 Number and 1 Special Character"
Font-Italic="True" Font-Size="Small" ForeColor="Red"
ValidationExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])[A-Za-z\d$@$!%*?&]{8,}"
ControlToValidate="TextBoxNewPassword" Display="Dynamic" />
When I input "Hamlida123#" regex did'nt allow it. How to solve this?
You need to include the '#` character specifically in the regex, like so:
ValidationExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&#])[A-Za-z\d$@$!%*?&#]{8,}"
Demo
Based on your current regex, I assume that you are only allowing certain non-word characters, and so you would need to list every allowable character in your regex as shown above.
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