驗證中文的正則表達式 報錯
if (!preg_match('/^[\u4e00-\u9fa5\w\.]+@\w+(\.\w+){1,2}$/i', $user['email'])) {
? ?die('郵箱不合法');
}
\u4e00-\u9fa5表示中文utf-8編碼,用正則表達式檢測工具,測試語法沒問題.
Warning: preg_match(): Compilation failed: PCRE does not support \L, \l, \N{name}, \U, or \u at offset 3 in C:\wamp\www\learning php\test2.php on line?95
報錯\u寫法不支持.還有其他表示中文的寫法嗎
2016-01-17
還是自己靠的住...說明一下:
\u需要轉義 修改后-->\\\u
unicode編碼需要在正則表達式結尾加上u 完整版在下面,修改地方加了下劃線
if (!preg_match('/^[\\\u4e00-\\\u9fa5\w\.]+@\w+(\.\w+){1,2}$/iu', $user['email'])) {
? ?die('郵箱不合法');
}