how to validate an email address in javascript
function validateEmail(email)
{
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
console.log(validateEmail('[email protected]'));
how to validate an email address in javascript
function validateEmail(email)
{
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
console.log(validateEmail('[email protected]'));
Email validation using javascript
function checkEmail() {
var email = document.getElementById('txtEmail');
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value)) {
alert('Please provide a valid email address');
email.focus;
return false;
}
}
- Call the function on Email textbox
Email Validation in JavaScript
<!DOCTYPE html>
<html>
<head>
<title>Email validation</title>
<script type="text/javascript">
function email_funnction() {
var email = document.emailform.email.value;
if(email.indexOf('@')<=0){
document.getElementById('errormsg').innerHTML="Invalid your Email Address";
return false;
}
if ((email.charAt(email.length-4)!='.') && (email.charAt(email.length-3)!='.')) {
document.getElementById('errormsg').innerHTML="Invalid your Email Address";
return false;
}
}
</script>
</head>
<body>
<h1>Email Validation in javascript</h1>
<span id="errormsg"></span>
<form name="emailform" onsubmit="return email_funnction()">
<label>Email</label>
<input type="text" name="email" value="">
<input type="submit" name="" value="Submit">
</form>
</body>
</html>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us