// email

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}

// international tel number - strip out delimiters and check for tel number

function checkIntTel (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a valid tel number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\+\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The tel number contains illegal characters.";
  
    }
return error;
}

// tel number - strip out delimiters and check for 10 digits

function checkTel (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a tel number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The tel number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The tel number is the wrong length. Make sure you included an area code.\n";
    } 
return error;
}

// cell number - strip out delimiters and check for 10 digits

function checkCell (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a cell number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The cell number contains illegal characters.";
  
    }
    if (!(stripped.length == 10)) {
	error = "The cell number is the wrong length.\n";
    } 
return error;
}

// name - 4-10 chars, uc, lc, and underscore only.

function checkName (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a name.\n";
}

    var illegalChars = /\W\ /; // allow letters, numbers, and underscores
    if ((strng.length < 3)) {
       error = "The name is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The name contains illegal characters.\n";
    } 
return error;
}       

// surnname - 4-10 chars, uc, lc, and underscore only.
function checkSurname (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a surname.\n";
}


    var illegalChars = /\W\ /; // allow letters, numbers, and underscores
    if ((strng.length < 3)) {
       error = "The surname is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The surnname contains illegal characters.\n";
    } 
return error;
}       


// non-empty textbox
function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
  }
return error;	  
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}  