<!DOCTYPE html> <html> <head> <script> function check(){ var patten = /^[a-z|A-Z]{4}\d{2,6}$/; var qwer = document.getElementById("user").value; if(!patten.test(qwer)){ alert("输入有误"); }else{ alert("输入正确"); } return; } </script> </head> <body> <input type="test" id="user"> <input type="button" value="查询" onclick="check()"/> </body> </html>