Can someone help me furnish my PHP validation class? I want to reduce its size and make it easier to use.
<?php
class validate
{
function check_empty($name,$value)
{
if(!empty($value))
{
$msg="";
return array($name=>$value,$error=>0,$err_message=>$msg);
}
else
{
$value="";
$msg=$name.'field is empty';
return array($name=>$value,$error=>1,$err_message=>$msg);
}
}
function validate_email($value)
{
$value=test_input($value);
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
$msg='Invalid Email';
return array($val=>$value,$error=>1,$err_message=>$msg);
}
else
{
$msg='';
return array($val=>$value,$error=>0,$err_message=>$msg);
}
}
function validate_strings($value,$maxsize,$minsize)
{
if(strlen($value)>$maxsize)
{
$msg='input data is very long';
return array($val=>$value,$error=>1,$err_message=>$msg);
}
else if(strlen($value)<$minsize)
{
$msg='input data is too short';
return array($val=>$value,$error=>1,$err_message=>$msg);
}
else
{
if(preg_match('/[^a-z\s-\']/i',$value))
{
$msg='';
return array($val=>$value,$error=>0,$err_message=>$msg);
}
else
{
$msg='The string should only contain letters';
return array($val=>$value,$error=>1,$err_message=>$msg);
}
}
}
function validate_numbers($value)
{
if(preg_match('/[0-9]+/'))
{
$msg='';
return array($val=>$value,$error=>0,$err_message=>$msg);
}
else
{
$msg='Invalid input,only numbers required';
return array($val=>$value,$error=>1,$err_message=>$msg);
}
}
}
?>
test_input
function? \$\endgroup\$