
function emailValidater(str)
{

var j=0
var k=0
var flag=true

  a=str.charAt(0)
  var l=str.indexOf('@')
  var m=str.lastIndexOf('@')
  var n=str.indexOf('.')
  var r=str.lastIndexOf('.')
  var p=(l+1)
  var q=(str.length-1)  

  arr=new Array('`','\'','{','}','[',']','~','!','#','$','%','^','&','*','(',')','-','+','|','=',',','?','<','>','/', '\\' ,'"',':',';',' ')

  cap=new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')  

  // To check whether email field is blank.

  if(str=="")
  {
    alert("Email cannot be left blank")
    return(false);
  }

  // To check whether email id starts with space.

  else  
	 if(a==" ")
	  {
		alert("Email cannot start with a space")
		return(false);
	  }     
  
  // To check whether email id starts with a numeric value.

	  else
		  if(a=='0'||a=='1'||a=='2'||a=='3'||a=='4'||a=='5'||a=='6'||a=='7'||a=='8'||a=='9')
		  {
		    alert("Email cannot start with an integer value")
		    return(false);
		  }

  // To check whether email id starts with a dot.

		  else
			  if(a=='.')
			  {
			    alert("Email cannot start with a dot")
			    return(false);
			  }

  // To check whether the email id starts with '@' symbol.

			  else
				  if (a=='@')
				  {
				    alert("Email cannot start with '@' symbol")
				    return(false);
				  }

				  else
				  {
    // To check whether email id contains @ symbol.
 
				    for(var i=1;i<str.length;i++)
				    {
				      if(str.charAt(i)=='@')
				      {
						j=j+1
						if (j==1)
						{
						  k=i
						}
				      }
				    }

				    if(j<1)
				    {
				      alert("There is no '@' symbol in your Email ID")
				      return(false);
				    }

    // To check whether email id has more than one '@' symbol.

				    else    
					    if(l!=m)
					    {	
					      alert("More than one '@' symbol in Email ID")
					      return(false);
					    }

    // To check whether email id ends with '@'.

						else
							if (str.charAt(str.length-1)=='@')
						    {
						      alert("Email ID cannot end with a '@'")
						      return(false);
						    }

    // To check whether there is a dot in the email id.
    
						    else
							    if(n<0)
								{
							      alert("There is no dot in your email id")
							      return(false)
    } 
  
    // To check whether there is a dot in the email id before '@' symbol.
  
    else  
    if(n<l && n>0)
    {
      alert("There cannot be '.' before '@' in Email ID.")
      return(false);
    }

    // To check whether there is a dot in the email id immediately after '@' symbol.
    
    else
    if(n==p)
    {
      alert("There cannot be a dot immediately after '@' in your email id")
      return(false);
    }

    // To check whether email id ends with a dot.
	
    else        
    if(r==q)
    {
      alert("Email ID cannot end with a dot")
      return(false)
    }
	     
    else
    {

      for(var m=0;m<str.length;m++)
      {
// To check whether there are 2 dots side by side.
		 
	if(str.charAt(m)=='.')
	{
	  m=m+1
	  if(str.charAt(m)=='.')
	  {
	    alert("There cannot be 2 dots simultaneously in Email Id.")
	    return false;
	  }
	}

	// To check whether the email id contains any invalid characters.

	for(var l=0;l<arr.length;l++)
	{
	  if(str.charAt(m)==arr[l])
	  {
	    var c=arr[l]
	    flag=false
	    alert("Invalid character ' "+c+" ' in your Email ID.")
	    return false;
	  }
	}


       
      }
    }
  }
 }

