JS 判断中文和中文字符

2018-10-11
JavaScript
4317

判断中文

匹配中文字符的正则表达式

/[\u4e00-\u9fa5]/

判断字符串是否含有中文

function checkIncludeChinese(str) {
    return /.*[\u4e00-\u9fa5]+.*/.test(str);
}

判断中文字符

中文字符一般包括

。 ? ! , 、 ; : “ ” ‘ ' ( ) 《 》 〈 〉 【 】 『 』 「 」 ﹃ ﹄ 〔 〕 … — ~ ﹏ ¥

对应的正则

/[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/

判断字符串中是否有中文字符

var reg = /.*[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]+.*/

function checkIncludeChineseChar(str) {
    return reg.test(str);
}
扫码体验小程序版