This browser does not support basic Web standards, preventing the display of our site's intended design. May we suggest that you upgrade your browser?

Canned Validation

These functions can be put in any page you call or include. All you have to do is send it the post form a submited page. The function will pull out the values and check them for errors and missing data. All fields with bad data or missing data are put in the session under values witht the input name as the key. In order to use this function properly the following naming convention MUST BE USED! Text fields: txt Date fields: dt Year fields: yr Number fields: in Currency fields: am Email fields: em Feel free to add data types!

function Valid($check, $exempt = array()){
$_SESSION['values'] = "";
	$return = true;
	foreach($check as $key => $value){
	
	// any value with * at the end of the name is exempt
		if(strpos($key, "*")){
			array_push($exempt, $key);
		}
		//checks the type for problems
		if($value <> "" && !checktype($value, substr($key,0,2))){
			$return = false;
			$_SESSION['values'][$key] =1;
		}
		if(!in_array($key, $exempt)){
		if($value == NULL || $value == "" || 
                    ($value == "1" && 
                     substr($key, 0, 3) === "ddl")){
		        $return = false;
			$_SESSION['values'][$key] = 0;
		}
					
		}
	}
	return $return;
}

// check a passed value agenst a type and returns ture or false
	// type is gotten from the first 
        //two letters of the input name.
	// tx is a string and not checked.
function checktype($value, $type){
	$return = true;
	switch($type){
		// any value with the type in is an number
		case("in"): $return = is_numeric($value); 
                   break;
		// any value with the type dt is a date
		case("dt"): $return = isDate($value);
                 break;

		// any value with the type yr is a year
		case("yr"): 
             if(!is_numeric($value) || !checklen($value,4) ){ 
                 $return = false;} break;
		// any value with the type am is an amount
		case("am"):     
        if(!is_numeric($value)||(int)($value*100)<>$value*100){ 
              $return = false;}break;		
		// any value with the type em is an email
		case("em"):$return = checkemail($value); break;
		default: break;
	}
	return $return;
}

// checks date format
function isDate($date){
	list($m, $d, $y) = split('[/,-]', $date);
	if(!checklen($m,2)){
		$date = "0" .$m;
	}
	if(!checklen($d,2)){
		$d = "0".$d;
	}
	$day = false;
	$month = false;
	switch($m){
		case("01"): if($d > 31){$day = true;} break;
		case("02"): if($d > 29){$day = true;} break;
		case("03"): if($d > 31){$day = true;} break;
		case("04"): if($d > 30){$day = true;} break;
		case("05"): if($d > 31){$day = true;} break;
		case("06"): if($d > 30){$day = true;} break;
		case("07"): if($d > 31){$day = true;} break;
		case("08"): if($d > 31){$day = true;} break;
		case("09"): if($d > 30){$day = true;} break;
		case("10"): if($d > 31){$day = true;} break;
		case("11"): if($d > 30){$day = true;} break;
		case("12"): if($d > 31){$day = true;} break;
		default: $month = true;
	}
	if ($month || $day || !checklen($y,4)){
		 $result = false;
	}else{
		$result = true;
	}
	return $result;
}

// checks the length of a value
function checklen($value, $size){
	$len = strlen($value);
	return ($len == $size);
}

// reutrns the number of chars in a string
function charCount($char, $string){
	$cnt = explode($char, $string);
	return sizeof($cnt);
}



// - checks for valid email
function checkemail($email){
	$result = false;
	$atSign = strpos($email, "@");
	$period = strpos($email, ".");
	if($atSign !== false && $period !== false){
		$result = true;
	}
	return $result;
}
Excellence. Our Measure. Our Motto. Our Goal.