Often times you need to validate the e-mail address of your addressees, just before they want to send you a message. Here are the logical checks:
One or more characters before the "@"
An optional "[", because user@[255.255.255.0] is a valid e-mail
A sequence of letters, numbers, and periods, which are all valid domain or
IP address characters
A period followed by a 2-3 letter suffix
An optional "]"

Here is a function that validates this sequence:

function valid(form)
{
  var field = form.email; // email field
  var str = field.value; // email string
  var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
  var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
  if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
    alert("Thank your for your feedback."); // this is optional
    return true;
  }
  alert("\"" + str + "\" is an invalid e-mail!"); // this is also optional
  field.focus();
  field.select();
  return false;
}

 

Send mail to santhosh_emids@yahoo.com with questions or comments about this web site.
Last modified: November 16, 2000