<?php
class validation {
var $errors;
function __construct() {
$this->errors = array();
}
function empty_check($input, $message = "") {
if (empty($input)) {
$this->errors[] = $message;
return true;
}
if (strlen(trim($input)) < 1) {
$this->errors[] = $message;
return true;
}
return false;
}
function whole_number_check($input, $message = "") {
$result = preg_match("/^[0-9]+$/", $input );
if ($result) {
return true;
} else {
$this->errors[] = $message;
return false;
}
}
function decimal_number_check($input, $message = "") {
$result = preg_match("/^[0-9.]+$/", $input );
if ($result) {
if (substr_count($input,".") > 1) {
$this->errors[] = $message;
return false;
} else {
return true;
}
} else {
$this->errors[] = $message;
return false;
}
}
function text_check($input, $message = "") {
$result = preg_match("/^[a-zA-Z ]+$/", $input );
if ($result) {
return true;
} else {
$this->errors[] = $message;
return false;
}
}
function email_check($input, $message = "") {
$result = preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/", $input );
if ($result) {
return true;
} else {
$this->errors[] = $message;
return false;
}
}
function date_check($input, $message = "") {
$result = preg_match("/^[0-9]{4}+\-[0-9]{2}+\-[0-9]{2}+$/", $input );
if ($result) {
return true;
} else {
$this->errors[] = $message;
return false;
}
}
function errors_found() {
if (isset($this->errors) && count($this->errors) > 0) {
return true;
} else {
return false;
}
}
function list_errors($delim = '|') {
if (isset($this->errors) && count($this->errors) > 0) {
return implode($delim,$this->errors);
}
}
}