= 0; $i -= 2) { $checksum += $number[$i]; } for ($i = $length - 2; $i >= 0; $i -= 2) { $double = $number[$i] * 2; $checksum += ($double >= 10) ? $double - 9 : $double; } return ($checksum % 10 === 0); } public static function phone($number, $lengths = NULL) { if ( ! is_array($lengths)) { $lengths = array(7,10,11); } $number = preg_replace('/\D+/', '', $number); return in_array(strlen($number), $lengths); } public static function date($str) { return (strtotime($str) !== FALSE); } public static function alpha($str, $utf8 = FALSE) { return ($utf8 === TRUE) ? (bool) preg_match('/^\pL++$/uD', (string) $str) : ctype_alpha((string) $str); } public static function alpha_numeric($str, $utf8 = FALSE) { return ($utf8 === TRUE) ? (bool) preg_match('/^[\pL\pN]++$/uD', (string) $str) : ctype_alnum((string) $str); } public static function alpha_dash($str, $utf8 = FALSE) { return ($utf8 === TRUE) ? (bool) preg_match('/^[-\pL\pN_]++$/uD', (string) $str) : (bool) preg_match('/^[-a-z0-9_]++$/iD', (string) $str); } public static function digit($str, $utf8 = FALSE) { return ($utf8 === TRUE) ? (bool) preg_match('/^\pN++$/uD', (string) $str) : ctype_digit((string) $str); } public static function numeric($str) { $locale = localeconv(); return (bool) preg_match('/^-?[0-9'.$locale['decimal_point'].']++$/D', (string) $str); } public static function standard_text($str) { return (bool) preg_match('/^[\pL\pN\pZ\p{Pc}\p{Pd}\p{Po}]++$/uD', (string) $str); } public static function decimal($str, $format = NULL) { $pattern = '/^[0-9]%s\.[0-9]%s$/'; if ( ! empty($format)) { if (count($format) > 1) { $pattern = sprintf($pattern, '{'.$format[0].'}', '{'.$format[1].'}'); } elseif (count($format) > 0) { $pattern = sprintf($pattern, '+', '{'.$format[0].'}'); } } else { $pattern = sprintf($pattern, '+', '+'); } return (bool) preg_match($pattern, (string) $str); } }