日期:2014-05-16 浏览次数:20334 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <script type="text/javascript"> function a(){ var reg=/^[a-z0-9\s]+$/ig; var val=document.getElementById("txt").value; if(!reg.exec(val)){ alert(" The input is wrong!!"); }else{ alert("The input is right!!"); } } </script> <body> <input type="text" id="txt"/> <button onclick="a();">test</button> </body> </html>
------解决方案--------------------
\^[a-z0-9\s]+$\i
------解决方案--------------------
var pattern=/^[a-zA-z0-9 ]*$/ig; alert(pattern.test("a12 3")); alert(pattern.test("a1桌控快搜 3"));