js驗證漢字正則表達式
阿新 • • 發佈:2017-06-27
ava ack logs back body 表達式 color utf bsp
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> function subname() { var str = $("#input").val(); var han = /^[\u4e00-\u9fa5]+$/; if (str == ‘‘) { alert("請輸入漢字"); return false; }; if (!han.test(str)) { alert("不是漢字") return false; }; returntrue; }; </script> <form method="post" onsubmit="subname()"> <input type="text" id="input" value="" /> <button type="submit" id="btn">提交</button> </form> </body> </html>
效果圖:
js驗證漢字正則表達式