Email address not validating completely for example. i have a email field and i am validating it from jQuery validation plugin. when i put some like "abbcss" it says email is not valid. then i put "abbcss@g" the error is gone and as you can see the email is still not valid. for better understanding i put a fiddle here.
$(document).ready(function(e) {
$('#email').keyup(function(){
$('#checkform').validate();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="//getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/>
<script src="//cdn.jsdelivr.net/jquery.validation/1.15.0/jquery.validate.js"></script>
<form id="checkform">
<input id="email" type="email" name="email">
</form>
<hr>
<p>Try to put first "abcc" and click outside field </p>
<p>then try to put "abcc@gmail" and click outside field </p>
<p>it will consider it a valid email but actually it is not.</p>
any help regarding this issue will be appriciate.
Approach: You can validate Email using jQuery by using the regex pattern. Regex expression is used for search operation and they are special strings representing a pattern to be matched.
With that in mind, to generally validate an email address in JavaScript via Regular Expressions, we translate the rough sketch into a RegExp : let regex = new RegExp('[a-z0-9]+@[a-z]+\.
Javascript(JS) Email Validation without Regex Email Address string must contain "@" sign. "."(dot) must be last character in string to test. consecutive "." (dot) should not be there. Length of string must be at-least 2 characters long.
You can validate email by using jquery validation plugin add method
jQuery.validator.addMethod("validate_email", function(value, element) {
if (/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value)) {
return true;
} else {
return false;
}
}, "Please enter a valid Email.");
$('#checkform').validate({
rules: {
email: {
validate_email: true
},
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With