0
How to validate email. Using javascript in html form
2 Answers
+ 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!
+ 1
Thanks I got