simple email validation in javascript

Today, We want to share with you simple email validation in javascript.In this post we will show you form validation in javascript, hear for email id validation in javascript without regular expression we will give you demo and example for implement.In this post, we will learn about Validate Email Address with an example.

How to validate an email address in JavaScript (2021)

Example 1: simple email validation in javascript

//returns true if valid, false if not valid
function checkEmailAddress(user_email_address) {
  var re = /^(([^<>()[\]\\.,;:\[email protected]\"]+(\.[^<>()[\]\\.,;:\[email protected]\"]+)*)|(\".+\"))@((\[[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,}))$/;
  return re.test(user_email_address);
}

Free Live Chat for Any Issue

Example 2: form validation for email in js

<script>  
function validateform(){  
var name=document.yourfrmname.name.value;  
var password=document.yourfrmname.password.value;  
  
if (name==null || name==""){  
  alert("Name can't be blank");  
  return false;  
}else if(password.length<7){  
  alert("Password must be at least 7 characters long.");  
  return false;  
  }  
}  

Example 3: code for email verification in front end using javascript

function checkEmailAddress(user_email_address) {
    const re = /^(([^<>()\[\]\\.,;:\[email protected]"]+(\.[^<>()\[\]\\.,;:\[email protected]"]+)*)|(".+"))@((\[[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,}))$/;
    return re.test(String(user_email_address).toLowerCase());
}

Example 4: email regex javascript

/* JavaScript: validating email address */

isValidEmail("[email protected]_name.com"); // true

function isValidEmail(user_email_address) {
	var emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	return !!user_email_address && typeof user_email_address === 'string'
		&& user_email_address.match(emailformat)};
};

Example 5: validate email function

# Language: Perl

sub Validate_Email($)
{
   my $user_email_address = $_[0];
   my $successData = "";

   my $checkUserName = "^[[:alnum:]]+([.!#\$\%&'*+-\/=?^_'{|]?[[:alnum:]]+)*";
   my $checkDomainName = "@[[:alnum:]]+([.-]{1}[[:alnum:]]+)*";
   my $sEndRegex = "([.]{1}[[:alnum:]]+)+";

   #  Work
   #--------#

   if ($user_email_address =~ /$checkUserName$checkDomainName$sEndRegex$/) {
      $successData = "Good Luck Email is valid";
   }
   else {
      $successData = "Sorry, Email is not valid";
   }

   return $successData;
}

my $user_email_address = '[email protected]';
print "[Email:$user_email_address] : " . Validate_Email($user_email_address) . "\n";

# OUTPUT -> [Email:[email protected]] : Email is valid

Example 6: using email regex javascript

/* Answer to: "email regex javascript" */

ValidateEmail("[email protected]"); // Must be a string

function ValidateEmail(user_email_address) {
	var emailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(String(user_email_address).toLowerCase());
	if (user_email_address.match(emailformat)) {
    	alert("Nice Email!")
      	return true;
    };
    alert("Sorry, That's not an user email address?!")
    return (false);
};

Download

I hope you get an idea about username validation in javascript.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.