// JavaScript Document
<!--
function Form2_Validator(theForm)
{

  var alertsay = ""; // define for long lines
  // alertsay is not necessary for your code,
  // but I need to break my lines in multiple lines
  // so the code won't extend off the edge of the page
  
  
    // check to see if the name field is blank
  if (theForm.name.value == "")
  {
    alert("please enter your \"name\".");
    theForm.name.focus();
    return (false);
  }

  // require at least 3 characters be entered
  if (theForm.name.value.length < 3)
  {
    alert("please enter at least 3 characters in the \"name\" field.");
    theForm.name.focus();
    return (false);
  }

  // allow ONLY alphanumeric keys, no symbols or punctuation
  // this can be altered for any "checkOK" string you desire
  var checkOK = "A .'BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var checkStr = theForm.name.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("please enter only letters in the \"name\" field.");
    theForm.name.focus();
    return (false);
  }
  
 // check if email field is blank
 if (theForm.email.value == "")
  {
    alert("please enter your \"email address\".");
    theForm.email.focus();
    return (false);
  }

  // test if valid email address, must have @ and .
  var checkemail = "@.";
  var checkStr = theForm.email.value;
  var emailValid = false;
  var emailAt = false;
  var emailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkemail.length;  j++)
    {
      if (ch == checkemail.charAt(j) && ch == "@")
        emailAt = true;
      if (ch == checkemail.charAt(j) && ch == ".")
        emailPeriod = true;
	  if (emailAt && emailPeriod)
		break;
	  if (j == checkemail.length)
		break;
	}
	// if both the @ and . were in the string
    if (emailAt && emailPeriod)
    {
		emailValid = true
		break;
	}
  }
  if (!emailValid)
  {
    alert("your \"email address\" must contain an \"@\" and a \".\" ");
    theForm.email.focus();
    return (false);
  }
  
   // check if telephone field is blank
 if (theForm.telephone.value == "")
  {
    alert("please enter your contact \"telephone\" number.");
    theForm.telephone.focus();
    return (false);
  }

  // only allow numbers to be entered
  var checkOK = "0 +123456789";
  var checkStr = theForm.telephone.value;
  var allValid = true;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    if (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("please enter only digits and \"+\" in the \"telephone\" field.");
    theForm.telephone.focus();
    return (false);
  }
  
   // check if no country has been selected
  if (theForm.country.selectedIndex < 0)
  {
    alert("please select your \"country\" of residence.");
    theForm.country.focus();
    return (false);
  }

  // check if the first drop down is selected, if so, invalid selection
  if (theForm.country.selectedIndex == 0)
  {
    alert("please select your \"country\" of residence.");
    theForm.country.focus();
    return (false);
  }
  
  // require that at least one selectenquiry be checked
  var checkSelected = false;
  for (i = 0;  i < theForm.selectenquiry.length;  i++)
  {
    if (theForm.selectenquiry[i].checked)
        checkSelected = true;
  }
  if (!checkSelected)
  {
    alert("please select at least one of the options that best describes your \"enquiry/ies\".");
    return (false);
  }
  
  // only allow up to 4 checkboxes be checked
  var checkCounter = 0;
  for (i = 0;  i < theForm.selectenquiry.length;  i++)
  {
    if (theForm.selectenquiry[i].checked)
        checkCounter = checkCounter + 1;
  }
  if (checkCounter > 4)
  {
    alert("please select only one or four of the options that best describes your \"enquiry/ies\".");
    return (false);
  }
  
    // check if briefenquiry field is blank 
    if (theForm.briefenquiry.value == "")
  {
    alert("please enter a \"brief description\".");
    theForm.briefenquiry.focus();
    return (false);
  }
  // allow only 500 characters maximum in the briefenquiry field
  if (theForm.briefenquiry.value.length > 500)
  {
    alert("please enter at most 500 characters in the \"brief description\" field.");
    theForm.briefenquiry.focus();
    return (false);
  }
  
    // because this is a sample page, don't allow to exit to the post action
  // comes in handy when you are testing the form validations and don't
  // wish to exit the page
  alertsay = "\"done.\""
  alert(alertsay);
  return (true);
  // replace the above with return(true); if you have a valid form to submit to
}
//-->
