I’m creating a password validator which takes any character but whitespaces and with at least 6 characters.
After searching the best I came up is this is this example:
What is the regular expression for matching that contains no white space in between text?
It disallows any spaces inbetween but does allow starting and ending with a space. I want to disallow any space in the string passed.
I tried this but it doesn’t work:
if (preg_match("/^[^\s]+[\S+][^\s]{6}$/", $string)) {
return true;
} else {
return false;
}
Thanks.
Something like this:
Can be quoted like:
All answers using
$are wrong (at least without any special flags). You should use\zinstead of$if you do not want to allow a line break at the end of the string.$matches end of string or before a line break at end of string (if no modifiers are used)\zmatches end of string (independent of multiline mode)From http://www.pcre.org/pcre.txt: