Posted inJavaScript / jQuery

email validation regex javascript – Regex to validate emails

here the best way to validate an email address in JavaScript Example. Regular Expression Pattern for email validation regex javascript /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.

email validation regex javascript

today I’ll learn to you how to use regular expression in js to validate or check email address. Here is the full source code to validate email address in JavaScript using regular expression.

Example of valid email id

Example of invalid email id

  • [email protected] [ an email should not be start with “.” ]
  • @you.me.net [ No character before @ ]
  • pakainfo()*@gmail.com [ here the regular expression only allows character, digit, underscore, and dash ]
  • [email protected] [double dots are not allowed]
  • pakainfo.domain_name.com [@ is not present]
  • [email protected] [ “.b” is not a valid tld ]
  • [email protected] [ tld (Top Level domain) can not start with dot “.” ]
  • [email protected] [ tld can not start with dot “.” ]

JavaScript code to validate an email id

function ValidateEmail(mail) 
{
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value))
  {
    return (true)
  }
    alert("You have entered an invalid email address!")
    return (false)
}

don’t miss : Simple Email Validation In Javascript

Example JavaScript function:

function validateEmail(email) 
    {
        var re = /\S+@\S+\.\S+/;
        return re.test(email);
    }
    
console.log(validateEmail('[email protected]'));

JavaScript Regular Expression Email Validation

var emailPattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/; 

Validate email address using JavaScript regular expression

function validateEmail(elementValue){      
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   return emailPattern.test(elementValue); 
 } 

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

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype