1

I need to change the X glyphicon,glyphicon-remove from https://getbootstrap.com/docs/3.3/components/ to a check glyphicon,glyphicon-ok if the input email is valid. So my question is how to know if an email inputed and checked by keyup is valued.

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');
            }
        });
Sanlyn
  • 139
  • 1
  • 12
  • Your regex won't accept my email address... Actually it will but only because you forgot to escape a `.`... – Niet the Dark Absol Apr 16 '19 at 10:24
  • What do you mean? – Sanlyn Apr 16 '19 at 10:27
  • Because it does not sufficiently match the email format. See: https://stackoverflow.com/questions/20771794/mailrfc822address-regex – Niet the Dark Absol Apr 16 '19 at 10:30
  • Consider instead using `` and checking its validity status. This offloads responsibility to the browser to do validation, and it will certainly do a better job than your regex! – Niet the Dark Absol Apr 16 '19 at 10:30
  • ill copy the assigment in my next comment. – Sanlyn Apr 16 '19 at 10:33
  • It should be checked whether the entered email address (ie. The box E-mail on a web form) valid form, that qualifies as a regular expression /^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i. In the event that a valid e-mail address to the user in the field with the identifier EmailValidateicon(element with a CSS class glyphicon glyphicon-okof the family Glyphicon ), otherwise the icon is displayed(element with a CSS class glyphicon glyphicon-remove). – Sanlyn Apr 16 '19 at 10:34
  • So, wait, is this homework? – Niet the Dark Absol Apr 16 '19 at 10:36
  • yes you could say that – Sanlyn Apr 16 '19 at 10:39

0 Answers0