js 判断是否含有中文

chunguangblog 2008-07-22 06:25:12
判断是否是中文没问题,可是要求判断是否含有中文该怎么做啊????如果含有中文汉字就合法否则不合法
...全文
670 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chunguangblog6 2008-07-22
  • 打赏
  • 举报
回复
function isChinese(){

var rname=/[\u4E00-\u9FA5]/; //u4E00-u9FA5 这是汉字编码范围,首先检测str是否在这个范围之内,是的话,返回true 否则false
var str=document.userinfo.address.value;
if(!rname.test(str)){
alert("必须含汉字!");
document.userinfo.address.focus();
}

}
lawrendc 2008-07-22
  • 打赏
  • 举报
回复
6楼 嗨~~
lawrendc 2008-07-22
  • 打赏
  • 举报
回复

<html>
<head>
<title></title>

</head>

<body>
<input type='text' onchange='test(this.value);'>
<script >
function test(inputValue)
{
var reg=/[\u4e00-\u9fa5]+/;
if(!reg.test(inputValue))
alert("不合法");

}
</script>
</body>
</html>
  • 打赏
  • 举报
回复
var rname=/[\u4E00-\u9FA5]/gi; 
if(!rname.test(document.form2.realname.value)) {
alert("必须含汉字!");
document.form2.realname.focus();
document.form2.realname.select();
return false;
}
  • 打赏
  • 举报
回复
看错了,还以为你不能含有汉字呢

var rname=/[\u4E00-\u9FA5]/; 
if(!rname.test(document.form2.realname.value)) {
alert("必须含汉字!");
document.form2.realname.focus();
document.form2.realname.select();
return false;
}
  • 打赏
  • 举报
回复
看错了,还以为你不能含有汉字呢

var rname=/[\u4E00-\u9FA5]/; 
if(!rname.test(document.form2.realname.value)) {
alert("必须含汉字!");
document.form2.realname.focus();
document.form2.realname.select();
return false;
}
  • 打赏
  • 举报
回复
var rname=/[\u4E00-\u9FA5]/; 
if( rname.test(document.form2.realname.value)) {
alert("不能含汉字!");
document.form2.realname.focus();
document.form2.realname.select();
return false;
}
  • 打赏
  • 举报
回复
var rname=/[\u4E00-\u9FA5]/;
if( rname.test(document.form2.realname.value)) {
alert("不能为汉字!");
document.form2.realname.focus();
document.form2.realname.select();
return false;
}

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧