// JavaScript Document
<!--
function Form1_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);
  }
  
    // require that at least one mediacomments be checked
  var checkSelected = false;
  for (i = 0;  i < theForm.mediacomments.length;  i++)
  {
    if (theForm.mediacomments[i].checked)
        checkSelected = true;
  }
  if (!checkSelected)
  {
    alert("please select any of the \"multimedia\" options you wish to \"comment\" on .");
    return (false);
  }
  
  // only allow up to 5 checkboxes be checked
  var checkCounter = 0;
  for (i = 0;  i < theForm.mediacomments.length;  i++)
  {
    if (theForm.mediacomments[i].checked)
        checkCounter = checkCounter + 1;
  }
  if (checkCounter > 5)
  {
    alert("please select only one or 5 of the \"multimedia\" options.");
    return (false);
  }
 
  // check if comments field is blank 
    if (theForm.comments.value == "")
  {
    alert("please enter your \"comments\".");
    theForm.comments.focus();
    return (false);
  }
  // allow only 500 characters maximum in the comments field
  if (theForm.comments.value.length > 500)
  {
    alert("please enter at most 500 characters in the \"comments\" field.");
    theForm.comments.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
}
//-->