允许alpha_numeric和符号preg_match PHP

时间:2012-11-24 05:52:55

标签: php regex preg-match

我有以下功能

public function alpha_custom($str) {
   return (! preg_match("/^([-a-z0-9_-])+$/i", $str)) ? FALSE : TRUE;
}

因此,如果字符串包含除字母数字字符,下划线或短划线以外的任何内容,则它将返回false。

现在我要添加以下内容:

  1. SPACE
  2. &
  3. ()
  4. .(期间)
  5. 请帮帮我。 谢谢。

1 个答案:

答案 0 :(得分:0)

return (preg_match('/[^a-z_\(\)\.\&\ \-0-9]/i', $str)) ? FALSE : TRUE;

修改 我用它来检查它对我有用

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

echo alpha_custom('ravi._ &');