I will rest today! I will write a verification of the hand-tear regular for everyone, which is generally used! js

* mailbox name allows Chinese characters, letters, numbers, underscores, domain names allowing only English domain name
* Mobile phone formats: Allow the beginning of 13,14,15,17,18 phone number
* Account Format: contain numbers, letters, , Underscore, length 6-15
* Password format: must uppercase letters, lowercase letters, numbers, length 6-12
login
<script>

    form1.onsubmit = function (e) {
        e.preventDefault();

        var emailReg = /^[A-Za-z0-9\u4e00-\u9fa5_]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;

        if (!emailReg.test(email.value)) { // 推荐这种写法
            // console.log(email.nextElementSibling);
            email.nextElementSibling.style.display = 'inline';
            return;
        } 
        email.nextElementSibling.style.display = 'none';


        var phoneReg = /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|17[6|7]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
        if (!phoneReg.test(phone.value)) {
            phone.nextElementSibling.style.display = 'inline';
            return;
        }
        phone.nextElementSibling.style.display = 'none';

        var accReg = /^[0-9a-zA-Z_]{6,15}$/;
        if (!accReg.test(account.value)) {
            account.nextElementSibling.style.display = 'inline';
            return;
        }
        account.nextElementSibling.style.display = 'none';


        var pwdReg = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{6,12}$/;
        if (!pwdReg.test(password.value)) {
            password.nextElementSibling.style.display = 'inline';
            return;
        }
        password.nextElementSibling.style.display = 'none';

        // 客户端验证通过后,再处理其他的业务逻辑。
        // 比如:将来还要把数据传递给服务器,让服务器那端再验证一次数据。双端验证,数据更安全。
        // 服务器验证成功后,返回相应的成功结果,如果验证不成功,返回不成功的结果。
        // 客户端根据客户端返回的结果做进一步的处理,如果验证不成功,不让登录,验证成功,跳转到登录后的主页。

    }

</script>

Guess you like

Origin blog.csdn.net/weixin_55973231/article/details/114761045