How to resolve any character in RegEx?

Current I use the following RegEx to enter a password for the user

^\w{8,16}$ 

Now, as I understand it, \ w only accepts the characters az, AZ, 0-9, and _. I want to do to allow ANY character, but the length should be between 8 and 16. How do I do this? Thanx a lot ahead :)

+6
regex
source share
2 answers

First, use the word count for what you need, and not for regular expression.

If you really need to, then .{8,16} should work .{8,16} matches a single char, no matter what it is.

EDIT: To preempt your next question, which will certainly be correct, then you can check out some of these blogs:

http://nilangshah.wordpress.com/2007/06/26/password-validation-via-regular-expression/

http://www.zorched.net/2009/05/08/password-strength-validation-with-regular-expressions/

OR just look at "checking passwords on the stack" in google

+9
source share

Try the following:

 ^.{8,16}$ 

A dot matches a single character, not caring about what that character is. The only exceptions are newline characters. By default, the dot will not match the newline character.

See http://www.regular-expressions.info/dot.html for more details.

+6
source share

All Articles