js 中文用户名验证代码

作者:简简单单 2011-07-29

function checkFormat(str)
{
if (escape(str).indexOf("%u")!=-1)
alert("不能含有汉字");
else if(str.match(/D/)!=null)
{
alert('不能含有字母');
}
}


只能用汉字操作

var str=document.getElementById("name").value;
var reg = /^[u4e00-u9fa5]+$/i;
if (!reg.test(str))
{
alert("请输入中文名字!");
document.form1.name.focus();
return false;
}
return true;

相关文章

精彩推荐