允许字母和数字符号与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._ &');
在&