Welcome to Snipped, a code gallery for creating, saving and sharing all kinds of code snippets.

Validate an Email Address

Javascript · February 16, 2017 6:39 pm

0 0 109

Front end validations are used for web applications while back-end validations protects us on the server side. Here is a regulation expression that does simple raw Javascript to validate an email address.

function checkEmail() {
var email = document.getElementById(’emailaddress’);
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;
}
}

Discuss this Snip
    No Discussion Comments found.

    You must be Signed In to discuss this Snip
Snipped

Snipped

Joined on
February 16, 2017

  • 9 Snips
    Contributed
  • 0 Likes
    Given
  • 0 Comments Posted
Snip Tags
Get Social And Share

Manage and share all of your code snippets in one easy place.