2012-11-24 151 views
0

我有以下功能允許的preg_match PHP

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

因此,如果字符串包含字母數字字符以外的任何其他alpha_numeric和符號,下劃線或破折號,那麼它將返回false。

現在我想添加以下內容:

  1. SPACE
  2. &
  3. ()
  4. .(期)

請幫助我。 謝謝。

回答

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._ &'); 
+0

失敗的'space'和'&' – Red

+0

嘗試編輯的代碼 – Ravi

+0

還在適應失敗的' &' – Red