正则用户名 /[a-zA-Z0-9_]+/密码 /(?=^.{5,}$)(?=.*\d)(?=.*\W+)(?=.*[A-Z])(?=.*[a-z])(?!.*\n).*$/var str = 'zhidao_20120616'; if( /[a-zA-Z0-9_]+/.test(str)){ alert('合法用户名'); }