window.onload = attachFormHandlers;

function attachFormHandlers() {
  if (document.getElementById) {
    form = document.getElementById("form1");
    form.onsubmit = function(){return validate();};

  }
}

function validate() { 

    var formInputs = document.getElementsByTagName("input");
    for (i=0; i<=formInputs.length; i++) {
        if (formInputs[i].getAttribute("class") == "v-email") {
          email = formInputs[i].value;
          if (!checkEmail(email)) return false;
        }
    }
}

function checkEmail(email) {
    var regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	// do the comparison, if we have a match return true, otherwise give message and return false
    if (regex.test(email)) {
        return true;
    } else {
        alert("Please check your email address and make sure it is valid.");
        return false;
    }
}


