validate an email address from a form field - version 2

This javascript function will check if the email address in the text box has an @ and a . in it and return a message saying if its valid or not. 

This is pretty basic as it only includes checking if the string has an @ and a . but not the position of them. 


<input type="email" id="email_check"> <button onclick="validate_email();" class="btn btn-primary">Validate Email</button>


<script src=""></script>


function validate_email() {
  	var emailfield = document.getElementById('email_check').value;
    // does the string have an @?
    if(!emailfield.includes("@")) {
      alert("Missing the @");
      return false;

      // does the string have a .?
    if(!emailfield.includes(".")) {
      alert("Missing the .");
      return false;
    // if we get to here, then the string has an @ and a dot, 
    // the email address could still look like this though...
    // @@@@......@@@@@
    // which is not valid, but its still better than nothing...
  	alert("Email appears to be valid");
  	return true;

External Link for validate an email address from a form field - version 2

Other Items in javascript

No Items Found.

Add Comment
Type in a Nick Name here
Page Views

This page has been viewed 116 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
time you enjoyed wasting is not wasted time