php - How do I allow spaces in this regex? -
i'm such amateur @ regex, how allow spaces(doesn't matter how many) in regex?
if(preg_match('/[^a-za-z0-9_-]/', $str)) return false;
if(preg_match('/[^a-za-z0-9_ -]/', $str)) return false;
note put space before hyphen. if space after hyphen, specifying character range underscore space. (issue evadable putting backslash before hyphen escape it.)
this assuming mean "allow" is: regex being used validate character string, , if matches, character string disallowed (hence return false
). characters in negated character class ([^...]
) allowed characters. (this causing general confusion in question.)
Comments
Post a Comment