电子邮件验证jquery mvc无效?

时间:2017-09-21 13:25:10

标签: javascript jquery html html5 css3

此代码中的电子邮件验证jquery mvc函数无效..

var CompanyName = $("#txtCompanyName").val();
            var Email = $("#txtEmail").val();
            var Country = $("#Country").val();

            if (CompanyName.length == 0) {
                alert("textbox value can't be empty");
                document.getElementById('txtCompanyName').style.border = "solid 1px red";
                $("#txtCompanyName").focus();
            }
            else if (Email.length == 0) {
                var email = document.getElementById('txtEmail').value;
                var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;
                if (reg.test(email)) {
                    alert("Valid");
                }
                else {
                    alert("In Valid");
                }
            }

            else if (Country.length == 0) {
                alert("Country value can't be empty");
                document.getElementById('Country').style.border = "solid 1px red";
                $("#Country").focus();
            }

1 个答案:

答案 0 :(得分:0)

两个符号符号就是问题所在。

var reg = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/;