File indexing completed on 2024-12-22 05:33:09

0001 <?php
0002 
0003 /**
0004  * Flooer Framework
0005  *
0006  * LICENSE: BSD License (2 Clause)
0007  *
0008  * @category    Flooer
0009  * @package     Flooer_Utility
0010  * @author      Akira Ohgaki <akiraohgaki@gmail.com>
0011  * @copyright   Akira Ohgaki
0012  * @license     https://opensource.org/licenses/BSD-2-Clause  BSD License (2 Clause)
0013  * @link        https://github.com/akiraohgaki/flooer
0014  */
0015 
0016 /**
0017  * Usage
0018  *
0019  * $bool = Flooer_Utility_Validation::isUri($uri);
0020  */
0021 
0022 /**
0023  * Validator class
0024  *
0025  * @category    Flooer
0026  * @package     Flooer_Utility
0027  * @author      Akira Ohgaki <akiraohgaki@gmail.com>
0028  */
0029 class Flooer_Utility_Validation
0030 {
0031 
0032     /**
0033      * Check for an IP address
0034      *
0035      * @param   string $ip
0036      * @return  bool
0037      */
0038     public static function isIp($ip)
0039     {
0040         if (filter_var($ip, FILTER_VALIDATE_IP)) {
0041             return true;
0042         }
0043         return false;
0044     }
0045 
0046     /**
0047      * Check for a URI address
0048      *
0049      * @param   string $uri
0050      * @return  bool
0051      */
0052     public static function isUri($uri)
0053     {
0054         //if (filter_var($uri, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED)) {
0055         //    return true;
0056         //}
0057         if (preg_match("/^(https?|ftps?|davs?|file)(:\/\/[\w\.\~\-\/\?\&\+\=\:\;\@\%\,]+)$/" , $uri)) {
0058             return true;
0059         }
0060         return false;
0061     }
0062 
0063     /**
0064      * Check for an email address
0065      *
0066      * @param   string $email
0067      * @return  bool
0068      */
0069     public static function isEmail($email)
0070     {
0071         //if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
0072         //    return true;
0073         //}
0074         if (preg_match("/^([\.\+\w\_\-]+@[\.\w\-]+\.[a-zA-Z]+)$/", $email)) {
0075             return true;
0076         }
0077         return false;
0078     }
0079 
0080     /**
0081      * Check for alphanumeric characters
0082      *
0083      * @param   string $alnum
0084      * @return  bool
0085      */
0086     public static function isAlnum($alnum)
0087     {
0088         if (ctype_alnum((string) $alnum)) {
0089             return true;
0090         }
0091         return false;
0092     }
0093 
0094     /**
0095      * Check for alphabetic characters
0096      *
0097      * @param   string $alpha
0098      * @return  bool
0099      */
0100     public static function isAlpha($alpha)
0101     {
0102         if (ctype_aplha((string) $alpha)) {
0103             return true;
0104         }
0105         return false;
0106     }
0107 
0108     /**
0109      * Check for numeric characters
0110      *
0111      * @param   string $digit
0112      * @return  bool
0113      */
0114     public static function isDigit($digit)
0115     {
0116         if (ctype_digit((string) $digit)) {
0117             return true;
0118         }
0119         return false;
0120     }
0121 
0122     /**
0123      * Check for the length of a string
0124      *
0125      * @param   string $string
0126      * @param   int $mini
0127      * @param   int $max
0128      * @return  bool
0129      */
0130     public static function isLength($string, $mini = 1, $max = 255)
0131     {
0132         $length = strlen($string);
0133         if ($length >= $mini && $length <= $max) {
0134             return true;
0135         }
0136         return false;
0137     }
0138 
0139 }