我如何检查电子邮件是否有效

时间:2019-04-16 10:21:48

标签: javascript html node.js email

如果输入电子邮件有效,我需要将X glyphicon,glyphicon-remove从https://getbootstrap.com/docs/3.3/components/更改为check glyphicon,glyphicon-ok。因此,我的问题是如何知道由keyup输入和检查的电子邮件是否有价值。

var emailRegex = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i

        document.getElementById("Email").addEventListener("keyup", 
        function() {
            var email = document.getElementById("Email").value;
            if (emailRegex.test(email)) {
                document.getElementById("EmailValidate").classList.remove('glyphicon,glyphicon-remove');
                document.getElementById("EmailValidate").classList.add('glyphicon,glyphicon-ok');
            }
        });

0 个答案:

没有答案