<script type="text/javascript">
var str = "sss_ss";
//长度判断
var preg = /^\w{6,12}$/;
//必须包含两种类型
var preg1 = /([\da-zA-Z]+?[_]+?)|([_]+?[\da-zA-Z]+?)|(\d+?[a-zA-Z]+?)|([a-zA-Z]+?\d+?)/;
var bb = preg.test(str);
var aa= preg1.test(str);
if(bb && aa){
alert(str+'用户名符合');
}else{
alert(str+'用户名不符合');
}
</script>
转载于:https://my.oschina.net/u/1773681/blog/667058