31 const IS_ALPHANUM =
'/^[\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]+$/mu';
69 $this->is_obj = is_object(
$obj);
70 $this->obj = (object)
$obj;
91 foreach (
$rules as $field => $fRule){
92 $value = isset(
$obj->$field)?
$obj->$field:null;
94 foreach ($fRule as $ruleName => $param) {
96 $ruleName = is_integer($ruleName) && is_string($param)?$param:$ruleName;
98 $param = is_array($param)?$param:array();
100 if($ruleName[0] ==
'@' and $this->is_obj){
101 $ruleName = ltrim($ruleName,
'@');
102 if(!
$obj->$ruleName($param)){
103 $this->messages[] = isset($param[
'error']) ?
104 $param[
'error']:
"El campo '$field' no es válido";
107 }elseif($ruleName[0] !=
'@' && !self::$ruleName($value, $param)){
108 $this->messages[] = isset($param[
'error']) ? $param[
'error']:
"El campo '$field' no es válido";
113 return empty($this->messages);
126 return $val->exec() ?
false:$val->getMessages();
136 return is_numeric($check);
145 public static function int($check)
147 return filter_var($check, FILTER_VALIDATE_INT);
161 $max= isset($param[
'max'])?$param[
'max']:0;
162 return !isset($value[$max]);
173 public static function range($value, $param)
175 $min = isset($param[
'min']) ? $param[
'min'] : 0;
176 $max = isset($param[
'max']) ? $param[
'max'] : 10;
177 $int_options = array(
'options' => array(
'min_range'=>$min,
'max_range'=>$max));
178 return filter_var($value, FILTER_VALIDATE_INT, $int_options);
189 public static function selet($value, $param)
191 $list = isset($param[
'list']) && is_array($param[
'list']) ? $param[
'list'] : array();
192 return in_array($value, $list);
202 return filter_var($mail, FILTER_VALIDATE_EMAIL);
213 $flag = isset($param[
'flag'])? $param[
'flag'] : 0;
214 return filter_var(
$url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED | $flag);
223 public static function ip($ip, $flags = FILTER_FLAG_IPV4)
225 return filter_var($ip, FILTER_VALIDATE_IP, $flags);
236 return !empty($check) && $check!=
'0';
248 return self::pattern($string, self::IS_ALPHANUM);
259 public static function date($value, $format =
'd-m-y')
262 $separator = str_replace(array(
'd' ,
'm' ,
'y'),
'', $format);
263 $separator = $separator[0];
264 if ($separator && substr_count($value, $separator) == 2) {
265 switch (str_replace($separator,
'', $format)) {
267 list ($day, $month, $year) = explode($separator, $value);
270 list ($month, $day, $year) = explode($separator, $value);
273 list ($year, $month, $day) = explode($separator, $value);
278 if (ctype_digit($month) && ctype_digit($day) && ctype_digit($year)) {
279 return checkdate($month, $day, $year);
292 public static function pattern($check, $param)
294 $regex = isset($param[
'regex'])? $param[
'regex'] :
'/.*/';
295 return filter_var($check, FILTER_VALIDATE_REGEXP, array(
'options' => array(
'regexp' =>
$regex)));
305 public static function decimal($value, $param)
307 $decimal = isset($param[
'decimal'])? $param[
'decimal'] :
',';
308 return filter_var($value, FILTER_VALIDATE_FLOAT, array(
'options' => array(
'decimal' => $decimal)));