Regular expression to check special character
-
I need to check whether password has at least 6 characters with at least 1 letter and one special character. I am checking the condition !Regex.IsMatch(strPassword,"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,24})$"). But it doesnot allow special character. I need to change the expression to check if there is at least one special character. Please help me out.
-
I need to check whether password has at least 6 characters with at least 1 letter and one special character. I am checking the condition !Regex.IsMatch(strPassword,"(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,24})$"). But it doesnot allow special character. I need to change the expression to check if there is at least one special character. Please help me out.
^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[^a-zA-Z0-9]).{6,}$
- ^ checks for the start of the input string.
- (?=.*[a-zA-Z]) checks that there are at least one letter.
- (?=.*[0-9]) checks that there are at least one digit.
- (?=.*[^a-zA-Z0-9]) checks that there are at least one special character (not a letter nor digit).
- .{6,} checks that there are at least 6 characters.
- $ checks for the end if the input string.
See also
-- MizardX (so)