js 验证是否为中文

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>js 验证是否为中文</title>
</head>

<body>
    <input type="text" id="text" />
    <button onclick="check()">检查</button>
    
    <script language="javascript"> 
    function check(){
        var text = document.getElementById("text");
        if(isChinese(text.value)){
            alert("是中文");
        }else{
            alert("不是中文");
        }
    }
    function isChinese(temp) { var re = /^[u4E00-u9FA5]+$/;
        if(re.test(temp)){
            return false;
        }
        return true;
    }
    </script>
</body>
</html>
posted @ 2012-07-16 17:28  Lellansin  阅读(587)  评论(0)    收藏  举报
魔舟网络 作者博客:lellansin@gmail.com