/**
 * Functions to validate form input on the Taproot Foundation site
 */

// Thanks to http://www.white-hat-web-design.co.uk/articles/js-validation.php
function valid_email(email) {
  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  if(reg.test(email) == false) return false;
  return true;
}

function valid_volunteer_password(p) {
  if (p.length < 4 || p.length > 20) return false;
  return true;
}

// This checks for a three-digit area code.
function valid_area_code(area_code) {
  var reg = /^[0-9]{3}$/;
  if(reg.test(area_code) == false) return false;
  return true;
}

// This checks for a seven-digit phone number (i.e., not the area code
// part).  The number may have a space, dot or hyphen between the
// third and fourth digit.
function valid_phone_number(phone) {
  var reg = /^[0-9]{3}[-. ]?[0-9]{4}$/;
  if(reg.test(phone) == false) return false;
  return true;
}

function valid_zipcode(z) {
  var zn = parseInt(z);
  if (! isNumeric(z) || z.length != 5 || zn < 0) return false;
  return true;
}
