Código PHP:
private function validateSTRING($value)
{
$return="El campo $this->field ";
if(isset($this->minchr) && strlen($value)<$this->minchr)
return $this->showValidation($return." debe tener como mínimo $this->minchr caracteres");
if(isset($this->maxchr) && strlen($value)>$this->maxchr)
return $this->showValidation($return." debe tener como máximo $this->maxchr caracteres");
if($this->accnum==0 && preg_match('`[0-9]`',$value))
return $this->showValidation($return." no puede contener números");
if($this->accnum==0 && preg_match('`[0-9]`',$value))
return $this->showValidation($return." no puede contener números");
if($this->accsp==0 && strpos($value," ")!==false)
return $this->showValidation($return." no puede contener espacios");
if(isset($this->like)) {
$last=(substr($this->like,0,1)=="%") ? true : false;
$first=(substr($this->like,-1)=="%") ? true : false;
$str=str_replace("%","",$this->like);
if($first && $last) {
if(strpos(strtolower($value),strtolower($str))===false)
return $this->showValidation($return." debe contener la cadena '$str'");
} elseif($first) {
if(strtolower(substr($value,0,strlen($str)))!=strtolower($str))
return $this->showValidation($return." debe comenzar por '$str'");
} elseif($last) {
if(strtolower(substr($value,-strlen($str)))!=strtolower($str))
return $this->showValidation($return." debe finalizar en '$str'");
}
}
return $this->showValidation();
}
private function formatSize($size) {
$sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return (round($size/pow(1024,($i=floor(log($size, 1024)))),2).$sizes[$i]);
}
private function validateFILE($value,$row)
{
$return="El campo $this->field ";
$size=$this->elements[$row]["value"]["size"];
$type=$this->elements[$row]["value"]["type"];
$minsize=(isset($this->minsize)) ? true : false;
$maxsize=(isset($this->maxsize)) ? true : false;
if($minsize && $maxsize)
if($size>$this->maxsize || $size<$this->minsize)
return $this->showValidation($return." debe tener un tamaño entre [".$this->formatSize($this->minsize)." , ".$this->formatSize($this->maxsize)."]");
if($minsize && !$maxsize)
if($size<$this->minsize)
return $this->showValidation($return." debe tener un tamaño mayor que ".$this->formatSize($this->minsize));
if($maxsize && !$minsize)
if($size>$this->maxsize)
return $this->showValidation($return." debe tener un tamaño menor que ".$this->formatSize($this->maxsize));
if(isset($this->accformats)) {
if(array_search($type, $this->accformats)===false) {
$string="[ ";
for($i=0;$i<count($this->accformats);$i++) {
$elements=explode("/",$this->accformats[$i]);
$string.=$elements[1]." , ";
}
$string=substr($string,0,-2)."]";
return $this->showValidation($return." debe tener formato $string");
}
}
return $this->showValidation();
}
private function unsetProperties()
{
$this->accnum="0";
$this->accsp="0";
$this->sql="0";
unset($this->field);
unset($this->min);
unset($this->max);
unset($this->type);
unset($this->min);
unset($this->max);
unset($this->numdec);
unset($this->sep);
unset($this->only);
unset($this->minchr);
unset($this->maxchr);
unset($this->tfh);
unset($this->like);
unset($this->minsize);
unset($this->maxsize);
unset($this->accformats);
unset($this->mindate);
unset($this->maxdate);
}
public function validateElements()
{
for($i=0;$i<$this->count;$i++)
{
$element=$this->elements[$i];
$this->field=$element["name"];
$this->valtype= isset($element["type"]) ? $element["type"] : "";
$force=$element["force"];
if(isset($element["valid"]))
{
if(array_search($element["value"],$element["valid"])===false)
$this->errors_in_validation.=$this->showValidation("El campo $this->field no es correcto");
else
$this->errors_in_validation.=$this->showValidation();
continue;
}
if(!is_array($element["value"]) && $this->valtype!="file")
$value=$element["value"];
else
$value=$element["value"]["name"];
if($force==0 && empty($value)) {
$this->errors_in_validation.=$this->showValidation();
continue;
}
if($force==1 && empty($value)) {
$this->errors_in_validation.=$this->showValidation("El campo $this->field es obligado");
continue;
}
foreach($element as $attr => $propertie)
$this->$attr=$element[$attr];
$function=strtoupper($this->valtype);
$function="validate".$function;
if($function=="validateFILE")
$this->errors_in_validation.=$this->$function($element["value"],$i);
else
$this->errors_in_validation.=$this->$function($element["value"]);
$this->unsetProperties();
}
return substr($this->errors_in_validation,0,-1);
}
}
?>
Y esta es la última parte del code.
Espero que sirva de algo!