Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I am trying to compare a string that is entered into a textbox on windows form as the text changes the checkboxes that represent the password strength will either check or uncheck.

It works fine for the the text length and updates properly but when compared to see if the password contains special characters such as &,#,$,_ etc.etc. using Regex.IsMatch it does not properly update here is part of the code I'm using.

Please tell me if this looks right?

C#
if (password.Length <= 3)
            {                
                if (Regex.IsMatch(password, @"/.[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]/", RegexOptions.ECMAScript))
                    {
                        Security = (SecurityLevel.Unsecure);
                        
                    }
                    else
                    {
                        Security = (SecurityLevel.None);
                    }
                }
Posted
Updated 8-May-11 18:51pm
v2

1 solution

try this Link is you want to restring the User to enter Special characters

Restrict user to Enter special characters[^]
 
Share this answer
 
Comments
charles henington 9-May-11 0:52am    
no im not trying to Restrict characters. I'm trying to determine if the password contains special characters and if so then update the password strength meter if characters exist
Mahendra.p25 9-May-11 1:11am    
try this Link

http://stackoverflow.com/questions/2279433/how-to-check-for-special-characters-using-regex
charles henington 9-May-11 3:23am    
Thanks Mahendra the second solution was exactly what i needed instead of
Regex.IsMatch(password, @"/.[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]/", RegexOptions.ECMAScript)
had to use
Regex.IsMatch(password, "^[!,@,#,$,%,^,&,*,?,_,~,-,£,(,)]+$", RegexOptions.ECMAScript)
Mahendra.p25 9-May-11 5:50am    
Welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900