2014-02-10 61 views
1

祝基於以下要求,以驗證用戶輸入:
PHP預浸匹配表達式

  • 必須是字母數字
  • 長於或等於五個字符

我已succeded與上述但我的其他兩個要求仍然存在:

  • Must ha VE UTF8字符åäöÅÄÖ
  • 必須允許點和斜線

    if(!(preg_match('/^\w{5,}$/', $username))) { return true; }

誰能幫助我擴展此表達對我的要求是什麼?

+1

[/\w.]{5,}添加點和斜槓。點擊此處查看UTF8的新增功能:http://www.regular-expressions.info/unicode.html – coln

+0

它必須擁有åäöÅÄÖ或必須允許åäöÅÄÖ? –

回答

2

使用Unicode化子性質:

if(!(preg_match('~^[\pL\pN./]{5,}$~u', $username))) { return true; } 

\pL代表任何字母
\pN代表任何數字。

+0

太棒了,沒有知道那些pL,pN存在。 – user3218338

+0

@ user3218338:很高興幫助。 – Toto

0

試試這個:

if(!(preg_match('/^[\w.\/]{5,}$/u', $username))) { return true; } 
+0

「。」(點)匹配任何字符...你必須逃避那也.. – Alex

+2

我在字符類中使用點,所以沒關係 – hindmost

+0

嗯..不知道那個作品...我必須檢查它... – Alex

0
if(!(preg_match('/^[a-zA-Z0-9.\/]{5,}$/', $username))) { return true; }