js验证表单输入必须为汉字

js验证表单输入必须为汉字

< script >
function  checkchinese()
{
   
var reg=/[^\x00-\x80]/;
   
var x=document.namefrom.xing.value;
   
if(!reg.test(x)){
       alert(
"请输入汉字!");
       document.namefrom.xing.focus();
       document.namefrom.xing.value 
= "";
       
return false;
   }

   
var m=document.namefrom.ming.value;
   
if(!reg.test(m)){
       alert(
"请输入汉字!");
       document.namefrom.ming.focus();
       document.namefrom.ming.value 
= "";
       
return false;
   }

}

< / script>
< form name = " namefrom "  method = " post "  action = " index.php "  onSubmit = ' return checkchinese(); ' >
< input type = text name = " xing " >
< input type = text name = " ming " >
< input type = " submit "  value = " 检查 " >
< / form>
用正则表达式/[\u4E00-\u9FA5]/表示中文

你可能感兴趣的:(js)