<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <mce:script type="text/javascript"><!-- function tests(){ //var aa = /^[^a-zA-Z0-9/_/u4e00-/u9fa5]$/; var aa = /^(?:[/u4e00-/u9fa5]*/w*/s*)+$/; var name = document.getElementById("name").value if(!aa.test(name)){ alert("包含非法字符"); return; }else{ alert("您的输入合法!"); } } // --></mce:script> <body> <form> <input type="text" id="name" name="name"> <input type="button" id="btn" name="btn" value="测试" οnclick="tests();" /> </form> </body> </html>