Evaluate my regex pleeze?
View Single Post
05-04-2008, 11:12 PM
Join Date: Apr 2007
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:
will successfully allow the string
. To disallow the newline, use the
(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.
View Public Profile
Send a private message to Salathe
Visit Salathe's homepage!
Find More Posts by Salathe