You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function CheckIsChinese(data) {
let ret = true;
for (let index = 0; index < data.length; index++) {
if (data.charCodeAt(index) < 0x4e00 || data.charCodeAt(index) > 0x9fa5) {
ret = false;
break;
}
}
return ret;
}
function CheckIsAllChinese(data) {
let reg = /[^\u4e00-\u9fa5]/g;
return !reg.test(data)
}
Activity
mlgzzz commentedon May 7, 2019
haizhilin2013 commentedon May 7, 2019
@mlgzzz 能解释下正则的意思吗?尤其是\u4e00-\u9fa5,从何得来的?
mlgzzz commentedon May 7, 2019
使用的
Unicode
编码4e00
和9fa5
分别表示第一个汉字和最后一个汉字的编码myprelude commentedon Jun 13, 2019
Konata9 commentedon Aug 5, 2019
由于中文比较特殊,最稳妥的还是使用
unicode
来进行匹配。这两个unicode
分别表示第一个和最后一个汉字。如果只是很粗暴的需要匹配汉字的话,可以使用
\W
,这样也能摘出汉字。不过会混杂逗号、句号等符号。15190408121 commentedon Sep 1, 2019
function chinese(str) {
return /^[\u4e00-\u9fa5]+$/.test(str);
}
chinese("我完全爱上Warma了");
yunlzhang commentedon Oct 21, 2019
按照中文字符对应编写正则
/[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF\U00020000-U0002EBEF]/
smile-2008 commentedon Sep 21, 2020
function isChinese(str) {
const re = /^[\u4e00-\u9fa5]+$/;
return re.test(str);
}
378406712 commentedon May 12, 2021
function reg(str){
const regExp =/[\u4e00-\u9fa5]/g
return regExp.test(str)
}
amikly commentedon Nov 9, 2021
github-cxtan commentedon Feb 18, 2022
function CheckIsChinese(data) {
let ret = true;
for (let index = 0; index < data.length; index++) {
if (data.charCodeAt(index) < 0x4e00 || data.charCodeAt(index) > 0x9fa5) {
ret = false;
break;
}
}
return ret;
}
function CheckIsAllChinese(data) {
let reg = /[^\u4e00-\u9fa5]/g;
return !reg.test(data)
}
yxllovewq commentedon Mar 9, 2022
xiaoqiangz commentedon May 27, 2022
// 判断字符是否是中文
var str6 = '我是n是啊nasd我'
function isCn(str) {
let data = str6.split('')
return data.map((v, i) => {
return v.charCodeAt() > 255
})