js to determine whether the string is Chinese

method 1:

function isChinese(temp){
    var re=/[^\u4E00-\u9FA5]/;
    if (re.test(temp)) return false ;
    return true ;
}

Method 2:

function isChn(str){
    var reg=/^[\u4E00-\u9FA5]+$/;
    if (!reg.test(str)){
        alert( "不全是中文" );
        return false ;
    }else{
        alert( "全是中文" );
        return true ;
    }
}

Method 3:

function funcChina(){
    var obj = document.form1.txtName.value;
    if (/.*[\u4e00-\u9fa5]+.*$/.test(obj)){
        alert( "不能含有汉字!" );
        return false ;
    } else {
        return true ;
    }
}

Method 4:

function isChina(s){
    var patrn=/[\u4E00-\u9FA5]|[/uFE30-/uFFA0]/gi;
    if (!patrn.exec(s)){
        return false ;
    } else {
        return true ;
    }
}

Method 5:

function isChina(s){
    var str= '玄峰软件www.exfsoft.com' ;
    if (escape(str).indexOf( "%u" )<0){
        alert( "没有包含中文" );
    } else {
        alert( "包含中文" );
    }
}

Guess you like

Origin blog.csdn.net/weixin_41542329/article/details/128223679