祝基於以下要求,以驗證用戶輸入:
PHP預浸匹配表達式
- 必須是字母數字
- 長於或等於五個字符
我已succeded與上述但我的其他兩個要求仍然存在:
- Must ha VE UTF8字符åäöÅÄÖ
必須允許點和斜線
if(!(preg_match('/^\w{5,}$/', $username))) { return true; }
誰能幫助我擴展此表達對我的要求是什麼?
祝基於以下要求,以驗證用戶輸入:
PHP預浸匹配表達式
我已succeded與上述但我的其他兩個要求仍然存在:
必須允許點和斜線
if(!(preg_match('/^\w{5,}$/', $username))) { return true; }
誰能幫助我擴展此表達對我的要求是什麼?
使用Unicode化子性質:
if(!(preg_match('~^[\pL\pN./]{5,}$~u', $username))) { return true; }
\pL
代表任何字母
\pN
代表任何數字。
太棒了,沒有知道那些pL,pN存在。 – user3218338
@ user3218338:很高興幫助。 – Toto
if(!(preg_match('/^[a-zA-Z0-9.\/]{5,}$/', $username))) { return true; }
[/\w.]{5,}添加點和斜槓。點擊此處查看UTF8的新增功能:http://www.regular-expressions.info/unicode.html – coln
它必須擁有åäöÅÄÖ或必須允許åäöÅÄÖ? –