Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't detect '#' as special key (Regex Asp.net)

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)(?=.*[$@$!%*?&amp;])[A-Za-z\d$@$!%*?&amp;]{8,}"
                    ControlToValidate="TextBoxNewPassword" Display="Dynamic" />

When I input "Hamlida123#" regex did'nt allow it. How to solve this?

like image 363
Ana Avatar asked Dec 04 '25 10:12

Ana


1 Answers

You need to include the '#` character specifically in the regex, like so:

ValidationExpression="^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&amp;#])[A-Za-z\d$@$!%*?&amp;#]{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.

like image 165
shree.pat18 Avatar answered Dec 07 '25 00:12

shree.pat18



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!