截取中文字符防止乱码
js:
var pattern = /^[".chr(0xa1)."-".chr(0xff)."a-zA-Z_]{3,18}$/, str = ''; console.log(pattern.test(str));
php:
$str = ''; $isMatched = preg_match('/^[".chr(0xa1)."-".chr(0xff)."a-zA-Z_]{3,18}$/', $str, $matches); var_dump($isMatched, $matches);