<!-- 
/*
Changes:  Sandeep V. Tamhankar (stamhankar@hotmail.com)

   1.1.2: Fixed a bug where trailing . in e-mail address was passing
            (the bug is actually in the weak regexp engine of the browser; I
            simplified the regexps to make it work).
   1.1.1: Removed restriction that countries must be preceded by a domain,
            so abc@host.uk is now legal.  However, there's still the 
            restriction that an address must end in a two or three letter
            word.
     1.1: Rewrote most of the function to conform more closely to RFC 822.
     1.0: Original

 This script and many more are available free online at 
 The JavaScript Source!! http://javascript.internet.com
*/
 
function emailCheck (emailStr) 
{
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) 
	{
//		alert("Email address seems incorrect....check @ and .'s  (i.e. myName@towson.edu)")
		alert("Email address is formatted incorrectly, please enter in the correct format (i.e. myName@towson.edu)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) 
	{
//        alert("The username doesn't seem to be valid (i.e. myName@towson.edu)")
        alert("Email address is formatted incorrectly, please enter in the correct format (i.e. myName@towson.edu)")
		return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{
	for (var i=1;i<=4;i++) 
	{
		if (IPArray[i]>255) 
		{
//		alert("Destination IP address is invalid! (i.e. myName@towson.edu)")
		alert("Email address is formatted incorrectly, please enter in the correct format (i.e. myName@towson.edu)")
		return false
		}
    }
    return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
	{
//		alert("The domain name doesn't seem to be valid (i.e. myName@towson.edu)")
		alert("Email address is formatted incorrectly, please enter in the correct format (i.e. myName@towson.edu)")
	    return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) 
		{
//		alert("The address must end in a three-letter domain, or two letter country (i.e. myName@towson.edu)")
		alert("Email address is formatted incorrectly, please enter in the correct format (i.e. myName@towson.edu)")
		return false
		}
	
	if (len<2) 
	{
	   var errStr="This address is missing a hostname! (i.e. myName@towson.edu)"
//	   alert(errStr)
 	   alert("Email address is formatted incorrectly, please enter in the correct format (i.e. myName@towson.edu)")
	   return false
	}

	return true;
}

//  End -->

