javscript 驗證 中文 非中文 包含中文

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<script language="javascript">
//判斷是否包含中文
function isChineseNo() {
var name = document.getElementById("name").value;
if (name.length == 0) {
return false;
}
for (i = 0; i < name.length; i++) {
if (name.charCodeAt(i) > 128) {
   alert("\u4e0d\u80fd\u5305\u542b\u6c49\u5b57");
};
}
//return false;
}

</script>
</head>

<body>
<input type="text" name="name" id="name" value="" />
<input type="button" name="button" value="button" οnclick="isChineseNo();" />
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章