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

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -