05-04-2008, 11:12 PM
|
#5 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
First off, it's a bad idea to suggest restricting passwords to only alphanumeric and underscore characters. People are advised to mix in other less common characters to give stronger passwords -- your code should accept good, strong passwords!
Going back to the original post, you say that the string should not have any whitespace characters but the $ will allow for one newline character at the end of the string: /^abcd$/ will successfully allow the string "abcd\n". To disallow the newline, use the D (PCRE_DOLLAR_ENDONLY) pattern modifier.
Since this is for passwords, why wouldn't you allow whitespace or quotes? On a more general note, be aware that patterns like the one provided in the original post will allow any other character except the ones specified (whitespace, single- and double-quote). For example, !!!! is a valid password as is ⌘☃ (two UTF-8 characters) when tested against the original pattern.
I'm not sure that a regular expression test is really very useful in this particular instance.
|
|
|
|