Email Validation onblur in JavaScript
Check Email Validation onblur event in Javascript –
In this example, I have checked email validation on onblur by regular expression.
- Add onblur event to input box.
<input type="email" name="email_id" id="email_id" value="" placeholder="abc@codeloveguru.com" maxlength="100" onblur="checkEmailValidation(this.value)">
- Here checkEmailValidation(str) function is defined and called on onblur event in the input box.
<script type="text/javascript">
function checkEmailValidation(str)
{
var regexp = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(!regexp.test(str))
alert("Please Enter a Valid E-mail Address!");
}
</script>
Email Validation onblur in JavaScript