js檢核字串是否還有中文及日文

by cactus77kiki

HTML

<script>
console.log(check('中'));
console.log(check('える'));	//false
console.log(check('中2'));
console.log(check('757'));
console.log(check('ß'));	//false
console.log('--another function');
console.log(chkContainCh('中'));
console.log(chkContainCh('える'));	//true
console.log(chkContainCh('中2'));
console.log(chkContainCh('757'));
console.log(chkContainCh('ß'));	//false
//檢核字串是否含有中文。含中文者,回傳true
function check(param){
	return param.search(RegExp("[一-" + String.fromCharCode(40869) + "]")) > -1;
}
//檢核字串是否含有中文。含中文、日文者,回傳true
function chkContainCh(param) {
    for (var i = 0; i < param.length; i++) {
        if (param.charCodeAt(i) >= 255) {            
            return true;
        }
    }
    return false;
}
</script>

JavaScript

/*
ref:
http://www.programmer-club.com.tw/showSameTitleN/javascript/1193.html
*/