开发者

How can I allow any character in a regular expression?

开发者 https://www.devze.com 2023-02-09 09:56 出处:网络
Currently, 开发者_如何转开发I use the following regular expression for the user to enter a password

Currently, 开发者_如何转开发I use the following regular expression for the user to enter a password

^\w{8,16}$

Now as I understand, \w only allows a-z, A-Z, 0-9, and the _ character (underscore). I want to do allow any character, but the length is to be between 8 and 16. How do I get about doing it?


Firstly, use a word count for what you need rather than regex.

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

EDIT: To preempt your next question which will surely be, what is a good password validation regular expression, you might want to 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 up 'password validation stackoverflow' on google


Try this:

^.{8,16}$

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

For the details, please visit The Dot Matches (Almost) Any Character.

0

精彩评论

暂无评论...
验证码 换一张
取 消