0

How to validate email. Using javascript in html form

20th Oct 2020, 9:40 AM
Shipu Dubey
Shipu Dubey - avatar
2 Respostas
+ 1
Hi, Good Morning. You can do that with an HTML type attribute equals to email. For example : <label for="email">Enter your email:</label> <input type="email" id="email" name="email"> <input type="submit"> It will validates the user when email is right or you get the message. Use regular expressions with JS for more custom validation of email. Ex:- <form name="form1" action="#"> <ul> <li><input type='text' class="text" name='text1'/></li> <li class="submit"><input type="submit" name="submit" value="Submit"/></li> </ul> </form> JS:- $('.submit').click(function(){ var text = $('.text').val(); var mailformat = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/; if(text.match(mailformat)) { alert("Valid email address!"); return true; } else { alert("You have entered an invalid email address!"); return false; } }); Hope you get it. Thanks!
21st Oct 2020, 4:09 AM
Shaili Shah
Shaili Shah - avatar
+ 1
Thanks I got
22nd Oct 2020, 4:27 AM
Shipu Dubey
Shipu Dubey - avatar