<html>
<head>
<title>中国站长天空-网页特效-表单特效-检测是否全部为中文</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
<body>
<!--把下面代码加到<body>与</body>之间-->
<script language="javascript">
function check()
{
var userName=document.getElementById("userName").value;
if(userName=="")
{
alert("不能为空!")
document.getElementById("userName").focus();
return false;
}
obj=userName.match(/^[\u4e00-\u9fa5]*$/g);
if(obj==null)
{
alert("必须为中文!")
document.getElementById("userName").value="";
document.getElementById("userName").focus();
return false;
}
else
{
alert("全部为中文!")
}
}
</script>
检测是否全部为中文:<input id="userName" type="text">
<input type="button" onclick="check()" value="检测">
</body>
</html>
<head>
<title>中国站长天空-网页特效-表单特效-检测是否全部为中文</title>
<meta http-equiv="content-Type" content="text/html;charset=gb2312">
</head>
<body>
<!--把下面代码加到<body>与</body>之间-->
<script language="javascript">
function check()
{
var userName=document.getElementById("userName").value;
if(userName=="")
{
alert("不能为空!")
document.getElementById("userName").focus();
return false;
}
obj=userName.match(/^[\u4e00-\u9fa5]*$/g);
if(obj==null)
{
alert("必须为中文!")
document.getElementById("userName").value="";
document.getElementById("userName").focus();
return false;
}
else
{
alert("全部为中文!")
}
}
</script>
检测是否全部为中文:<input id="userName" type="text">
<input type="button" onclick="check()" value="检测">
</body>
</html>
文章来源:http://www.zzsky.cn/effect/content/873.htm