function checkCH() {
var str = txtPwd.value;
var c = /[\u4e00-\u9fa5]/; // 中文 Unicode 範圍
if (c.test(str)) {
alert('不能輸入中文。');
return false;
}
return true;
}
<input type="text" id="txtPwd" onblur="return checkCH()" />
若需在輸入時即時移除中文,可綁定 input 事件:
$('#txtPwd').on('input', function(){
this.value = this.value.replace(/[\u4e00-\u9fa5]/g, '');
});
[\u4e00-\u9fa5] 僅涵蓋基本常用漢字,擴展區漢字(如 \u3400-\u4dbf)未包含,視需求擴展。