<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> 姓名:<input type="text" id="uname" /> </body> </html> <input type="button" onclick="check();" value="提交" /> <script> function check(){ if(!/^[\u4e00-\u9fa5]+$/gi.test(document.getElementById("uname").value)) alert("只能输入汉字"); else alert("提交成功"); } </script>