Email Check – Full Function

Email Check – Full Function

function checkEmailAddress(){
 // the HTML5 'email' input will do some of our checking for us.
 // however this does not solve old/incompliant browsers
 document.getElementById('emailResult').innerHTML = "checking...";
 email_entered = document.getElementById('emailAddress').value;
 length_of_email = email_entered.length;
 position_of_at  = email_entered.indexOf('@');
 another_at      = email_entered.indexOf('@',(position_of_at+1));
 position_of_dot = email_entered.indexOf('.');
 if(length_of_email<6 || position_of_at==-1 || position_of_dot==-1){
  // test 1
  document.getElementById('emailResult').innerHTML = "Invalid Email Address Entered";
 }
 else if(another_at>-1){
  // test 2 - multiple @ signs
  document.getElementById('emailResult').innerHTML = "You have entered multiple '@' signs. Please try again.";
 }
 else if(position_of_at==0 || position_of_dot==0){
  // the @ and the . cannot be at position 0 for it to be valid.
  document.getElementById('emailResult').innerHTML = "An Email address cannot start with an '@' or a '.'";
 }
 else{
  document.getElementById('emailResult').innerHTML = "This seems to be a valid email address.";
 }
}
Comments are closed.