include dot(.) and hyphen(-) in a regex

后端 未结 4 1104
误落风尘
误落风尘 2021-01-29 12:56
 if(preg_match(\'/[^a-z\\-0-9]/i\', $value))

    {
    echo \"\";
}

how

4条回答
  •  离开以前
    2021-01-29 13:06

    The hyphen does not need to be escaped if it is the last character in the Regex group. But the dot should always be escaped, so

    '/[^a-z\.0-9-]/i'
    

    Will check for a to z, . , 0 to 9 and - in that order, case insensitively.

提交回复
热议问题