KumbiaPHP beta2-dev
Framework PHP en español
|
00001 <?php 00022 class Validate 00023 { 00031 const IS_REQUIRED = '/[^\\s]/'; 00032 00033 /* 00034 * El valor deber ser solo letras y números 00035 */ 00036 const IS_ALPHANUM = '/^[\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]+$/mu'; 00037 00038 00039 00045 public static $error = NULL; 00051 public static $regex = NULL; 00058 public static function int ($check) 00059 { 00060 return filter_var($check, FILTER_VALIDATE_INT); 00061 } 00072 public static function maxLength($value, $max, $min = null) 00073 { 00074 $length = strlen($value); 00075 if($min and $length < $min){ 00076 return false; 00077 } 00078 return ($length <= $max); 00079 } 00088 public static function range($value, $min=0, $max=NULL) 00089 { 00090 $int_options = array('options'=> array('min_range'=>$min, 'max_range'=>$max)); 00091 return filter_var($value, FILTER_VALIDATE_INT, $int_options); 00092 } 00093 00102 public static function inList($value, $list) 00103 { 00104 return in_array($check, $list); 00105 } 00106 00113 public static function mail ($mail) 00114 { 00115 return filter_var($mail, FILTER_VALIDATE_EMAIL); 00116 } 00123 public static function url ($url) 00124 { 00125 return filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED); 00126 } 00133 public static function ip ($ip) 00134 { 00135 return filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); 00136 } 00143 public static function required($check) 00144 { 00145 return !empty($check) && $check!='0'; 00146 } 00153 public static function alphanum ($string) 00154 { 00155 return self::pattern($string, self::IS_ALPHANUM); 00156 } 00165 public static function date ($value, $format = 'd-m-y') 00166 { 00167 // busca el separador removiendo los caracteres de formato 00168 $separator = str_replace(array('d' , 'm' , 'y'), '', $format); 00169 $separator = $separator[0]; // el separador es el primer caracter 00170 if ($separator && substr_count($value, $separator) == 2) { 00171 switch (str_replace($separator, '', $format)) { 00172 case 'dmy': 00173 list ($day, $month, $year) = explode($separator, $value); 00174 break; 00175 case 'mdy': 00176 list ($month, $day, $year) = explode($separator, $value); 00177 break; 00178 case 'ymd': 00179 list ($year, $month, $day) = explode($separator, $value); 00180 break; 00181 default: 00182 return false; 00183 } 00184 if (ctype_digit($month) && ctype_digit($day) && ctype_digit($year)) { 00185 return checkdate($month, $day, $year); 00186 } 00187 } 00188 return false; 00189 } 00197 public static function pattern ($check, $regex) 00198 { 00199 return filter_var($check, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $regex))); 00200 } 00201 00209 public static function decimal($value, $decimal = ',') 00210 { 00211 return filter_var($value, FILTER_VALIDATE_FLOAT, array('options' => array('decimal' => $decimal))); 00212 } 00213 }