代码-JS之正则验证用户名

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

<script>
    //注册的时候,要求用户名:
    //长度4~10位
    //不能是纯数字
    //不能以数字打头
    //不能有特殊符号
    //不能是纯字母

    var username = 'a234ads';
    //var r =/^[a-z][a-z0-9]{3,9}$/gi;    //完成其他,下面再解决不能是纯字母
    //Every(?!n)[A-Z]  //匹配A-Z中排除了n的字符串
    var r = /(?!^[a-z]+$)^[a-z][a-z0-9]{3,9}$/gi; //使用环视,得到最终结果
    var result = r.test(username);
    console.log(result);

</script>

</body>
</html>

猜你喜欢

转载自blog.csdn.net/qq_39723600/article/details/83141018