Unable to detect "#" as special key (Regex Asp.net)
I am new to Asp. I have a problem using regex to validate password input. Here's 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 entered "Hamlida123 #" the regex did'nt allow it. How to solve this?
+3
source to share
1 answer
You need to specify the `#` character specifically in the regular expression, for example:
ValidationExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&#])[A-Za-z\d$@$!%*?&#]{8,}"
Based on your current regex, I am assuming that you only allow some non-word characters, and therefore you will need to list every valid character in your regex as shown above.
+3
source to share