在javascript中,要判断字符串是中文是很简单的。比如:
123456var
str =
"php编程"
;
if
(/^[\u4e00-\u9fa5]+$/.test(str)) {
alert(
"该字符串全部是中文"
);
}
else
{
alert(
"该字符串不全部是中文"
);
}
PHP正确匹配中文方式, “u" for utf-8 mode
123456$str =
"php编程"
;
if
(preg_match(
"/^[\x{4e00}-\x{9fa5}]+$/u"
,$str)) {
print(
"该字符串全部是中文"
);
}
else
{
print(
"该字符串不全部是中文"
);
}
I am a common boy from China... The blog will record my life, my happiness and my sorrow and whatever. It is really good place to share with you, my love and my friends. Now I am a husband, my wife is called Yuxia, a sweety girl. I am a father of two boys, weiheng and weibo. Grow up day by day!
Ubuntu 10.10 Pentax K-5
Saturday, December 02, 2017
regex 中文
Subscribe to:
Posts (Atom)