Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
允许字母和数字符号与PHP匹配_Php_Regex_Preg Match - Fatal编程技术网

允许字母和数字符号与PHP匹配

允许字母和数字符号与PHP匹配,php,regex,preg-match,Php,Regex,Preg Match,我有以下功能 public function alpha_custom($str) { return (! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE; } 因此,如果字符串包含字母数字字符、下划线或破折号以外的任何内容,那么它将返回false 现在我想添加以下内容: 空格 & (和) (句点) 请帮帮我。 谢谢 return(preg\u match('/[^a-z\(\)\.&\\-0-9]/i',$str))?假:

我有以下功能

public function alpha_custom($str) {
   return (! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE;
}
因此,如果字符串包含字母数字字符、下划线或破折号以外的任何内容,那么它将返回false

现在我想添加以下内容:

  • 空格
  • &
  • (句点)
  • 请帮帮我。 谢谢

    return(preg\u match('/[^a-z\(\)\.&\\-0-9]/i',$str))?假:真

    编辑 我用这个来检查,它对我有效

    function alpha_custom($str)
    {
       return (preg_match('/[^a-z_\(\)\.\&\ \-0-9]/i', $str)) ? 'FALSE' : 'TRUE';
    }
    
    echo alpha_custom('ravi._ &');
    

    &