| Server IP : 195.130.67.5 / Your IP : 216.73.216.231 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/Civil/includes/ |
Upload File : |
<?
class Validator
{
public $errors; // A variable to store a list of error messages
// Validate something's been entered
public function validateGeneral($theinput,$description = '')
{
if (trim($theinput) != "")
{
return true;
}
else
{
$this->errors[] = $description;
return false;
}
}
// Validate text only - supports unicode characters
public function validateTextOnly($theinput,$description = '')
{
$result = preg_match("/^[\p{L}\p{N}\ ]+$/u", $theinput );
if ($result)
{
return true;
}
else
{
$this->errors[] = $description;
return false;
}
}
// Validate text only, no spaces allowed - supports unicode characters
public function validateTextOnlyNoSpaces($theinput,$description = '')
{
$result = preg_match ("/^[\p{L}\p{N}]+$/u", $theinput );
if ($result)
{
return true;
}
else
{
$this->errors[] = $description;
return false;
}
}
// Validate email address
public function validateEmail($theinput, $description = '')
{
$result = preg_match( "/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/", $theinput );
if ($result)
{
return true;
}
else
{
$this->errors[] = $description;
return false;
}
}
// Validate numbers only (integer, floating signed or unsigned)
public function validateNumber($theinput,$description = '')
{
if (is_numeric($theinput)) {
return true; // The value is numeric, return true
}
else
{
$this->errors[] = $description; // Value not numeric! Add error description to list of errors
return false; // Return false
}
}
// Validate date
public function validateDate($thedate,$description = '')
{
if (strtotime($thedate) == false || $thedate == '')
{
$this->errors[] = $description;
return false;
}
else
{
return true;
}
}
public function validateEnglishDate($thedate,$description = '')
{
if (preg_match("/^\d\d\d\d-[0-1]\d-[0-3]\d$/",$thedate))
{
return true;
}
else
{
$this->errors[] = $description;
return false;
}
}
public function validateEnglishDateTime($thedate,$description = '')
{
if (preg_match("/^\d\d\d\d-[0-1]\d-[0-3]\d[ ][0-2]\d:[0-5]\d:[0-5]\d$/",$thedate))
{
return true;
}
else
{
$this->errors[] = $description;
return false;
}
}
public function validateGreekDate($thedate,$description = '')
{
if (preg_match("/^[0-3]\d-[0-1]\d-\d\d\d\d$/",$thedate))
{
return true;
}
else
{
$this->errors[] = $description;
return false;
}
}
public function validateGreekDateTime($thedate,$description = '')
{
if (preg_match("/^[0-3]\d-[0-1]\d-\d\d\d\d[ ][0-2]\d:[0-5]\d:[0-5]\d$/",$thedate))
{
return true;
}
else
{
$this->errors[] = $description;
return false;
}
}
// Check whether any errors have been found (i.e. validation has returned false)
// since the object was created
public function foundErrors()
{
if (count($this->errors) > 0)
{
return true;
}
else
{
return false;
}
}
// Return a string containing a list of errors found,
// Seperated by a given deliminator
public function listErrors($delim = ' ')
{
return implode($delim,$this->errors);
}
// Manually add something to the list of errors
function addError($description)
{
$this->errors[] = $description;
}
}
?>