
// check if date is valid and return true/false
function checkDate(myDayStr, myMonthStr, myYearStr){
	var validformat=/^\d{2}\/\d{2}\/\d{4}$/		//Basic check for format validity
	var returnval=false;
	var input = myMonthStr + '/' + myDayStr + '/' + myYearStr;
	if (!validformat.test(input)){
		returnval=false;
	} else{ //Detailed check for valid date ranges
		var monthfield=myMonthStr;
		var dayfield=myDayStr;
		var yearfield=myYearStr;
		var dayobj = new Date(yearfield, monthfield-1, dayfield);
		if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)){
			returnval=false;
		} else
			returnval=true;
	}
	return returnval;
}

// return trimmed string
function trim(mystring){
	return mystring.replace(/^\s+|\s+$/g, '') ;
}

// check if alphanumeric string - customised (not all letters)
function isAlphaNum(mystring)
{
	for(var j=0; j<mystring.length; j++)
		{
		  var alphaa = mystring.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh >= 97 && hh <= 102) || (hh >= 65 && hh <= 70) || (hh >= 48 && hh <= 57)) 
		  { //a-f or A-F or 0-9 are allowed
		  }
		else	{
			 return false;
		  }
		}
 return true;
}

// check if numeric string
function isNumeric(mystring)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < mystring.length && IsNumber == true; i++) 
      { 
      Char = mystring.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;   
}
