javascript determines whether a string and the string is free of Chinese Chinese punctuation

Determine whether a string is all Chinese, and commas, periods and the like are also distinguished in the English input state, as follows:

<input id="test" type="text" onblur="CheckChinese('test',this.value)" />
<script>
    function CheckChinese(obj,val){
        var reg = new RegExp("[\\u4E00-\\u9FFF]+$","g");
        if(!reg.test(val)){
            console.log('不是纯中文字符');
            var strObj = document.getElementById(obj);
            strObj.value = "";
            strObj.focus();
        }else{
             console.log('是纯中文字符');
        }
    }
</script>

Guess you like

Origin blog.csdn.net/wwj791859814/article/details/77990262
Recommended