- /**
- * Validation Class
- *
- * @lastmodify 2014-5-16
- * @author jy625
- */
- Class verifyaction{
- /**
- * is a null value
- */
- public static function IsEmpty ($STR) {
- $str = Trim ($STR);
- Return!empty ($STR)? True:false;
- }
- /**
- * Digital Verification
- * param: $flag: int is an integer, float is floating point type
- */
- public static function Isnum ($str, $flag = ' float ') {
- if (!self::isempty ($STR)) return false;
- if (Strtolower ($flag) = = = ' int ') {
- Return (string) (int) $str = = = (string) $str)? True:false;
- }else{
- Return (string) (float) $str = = = (string) $str)? True:false;
- }
- }
- /**
- * Name matching, such as user name, directory name, etc.
- * @param: String $str strings to match
- * @param: Whether $chinese support Chinese, default support, if it is a matching file name, it is recommended to turn off this item (FALSE)
- * @param: $charset encoding (default utf-8, support gb2312)
- */
- public static function Isname ($STR, $chinese = true, $charset = ' utf-8 ') {
- if (!self::isempty ($STR)) return false;
- if ($chinese) {
- $match = (Strtolower ($charset) = = ' gb2312 ')? "/^[". Chr (0XA1). " -". Chr (0xff)." a-za-z0-9_-]+$/":"/^[x{4e00}-x{9fa5}a-za-z0-9_]+$/u ";
- }else{
- $match = '/^[a-za-z0-9_-]+$/';
- }
- Return Preg_match ($match, $str)? True:false;
- }
- /**
- * Email Verification
- */
- public static function Isemail ($STR) {
- if (!self::isempty ($STR)) return false;
- Return Preg_match ("/([a-z0-9]*[-_\.]? [a-z0-9]+] *@ ([a-z0-9]*[-_]?[ a-z0-9]+) +[\.] [A-z] {2,3} ([\.] [A-z] {2})? /i ", $str)? True:false;
- }
- Mobile phone number Verification
- public static function IsMobile ($STR) {
- $exp = "/^13[0-9] [0-9]{8}$|15[012356789] small shellfish [0-9]{8}$|18[012356789] small shellfish [0-9]{8}$|14[57] small shellfish [0-9]$/];
- if (Preg_match ($exp, $str)) {
- return true;
- }else{
- return false;
- }
- }
- /**
- * URL authentication, plain URL format, IP authentication not supported
- */
- public static function Isurl ($STR) {
- if (!self::isempty ($STR)) return false;
- return Preg_match (' # (HTTP|HTTPS|FTP|FTPS)://([w-]+.) +[w-]+ (/[w-./?%&=]*)? #i ', $str)? True:false;
- }
- /**
- * Verify Chinese
- * @param: String $str strings to match
- * @param: $charset encoding (default utf-8, support gb2312)
- */
- public static function Ischinese ($str, $charset = ' utf-8 ') {
- if (!self::isempty ($STR)) return false;
- $match = (Strtolower ($charset) = = ' gb2312 ')? "/^[". Chr (0XA1). " -". Chr (0xff)." +$/"
- : "/^[x{4e00}-x{9fa5}]+$/u";
- Return Preg_match ($match, $str)? True:false;
- }
- /**
- * UTF-8 Verification
- */
- public static function IsUtf8 ($STR) {
- if (!self::isempty ($STR)) return false;
- Return (Preg_match ("/^ ([". chr (228). " -". Chr (233)." Beckham [". chr (128)." -". Chr (191)." Beckham [". chr (128)." -". Chr (191)." Beckham) Beckham/", $word)
- = = True | | Preg_match ("/[". chr (228). " -". Chr (233)." Beckham [". chr (128)." -". Chr (191)." Beckham [". chr (128)." -". Chr (191)." Beckham) $/", $word)
- = = True | | Preg_match ("/[". chr (228). " -". Chr (233)." Beckham [". chr (128)." -". Chr (191)." Beckham [". chr (128)." -". Chr (191)." Beckham) {2,}/", $word)
- = = True)? True:false;
- }
- /**
- * Verify Length
- * @param: String $str
- * @param: int $type (mode, default min <= $str <= max)
- * @param: int $min, Min., $max, maximum;
- * @param: String $charset character
- */
- public static function Length ($STR, $type =3, $min =0, $max =0, $charset = ' utf-8 ') {
- if (!self::isempty ($STR)) return false;
- $len = Mb_strlen ($str, $charset);
- Switch ($type) {
- Case 1://Match Minimum value only
- Return ($len >= $min)? True:false;
- Break
- Case 2://Match Max value only
- Return ($max >= $len)? True:false;
- Break
- Default://min <= $str <= Max
- Return (($min <= $len) && ($len <= $max))? True:false;
- }
- }
- /**
- * Verify Password
- * @param string $value
- * @param int $length
- * @return Boolean
- */
- public static function Ispwd ($value, $minLen =6, $maxLen =16) {
- $match = '/^[\\~!@#$%^&* ()-_=+|{}
- ,.? \/:;\ ' \d\w]{'. $minLen. ', '. $maxLen. '} $/';
- $v = Trim ($value);
- if (empty ($v))
- return false;
- Return Preg_match ($match, $v);
- }
- /**
- * Verify user name
- * @param string $value
- * @param int $length
- * @return Boolean
- */
- public static function Isnames ($value, $minLen =2, $maxLen =16, $charset = ' all ') {
- if (empty ($value))
- return false;
- Switch ($charset) {
- Case ' EN ': $match = '/^[_\w\d]{'. $minLen. ', '. $maxLen. '} $/iu ';
- Break
- Case ' CN ': $match = '/^[_\x{4e00}-\x{9fa5}\d]{'. $minLen. ', '. $maxLen. '} $/iu ';
- Break
- Default: $match = '/^[_\w\d\x{4e00}-\x{9fa5}]{'. $minLen. ', '. $maxLen. '} $/iu ';
- }
- Return Preg_match ($match, $value);
- }
- /**
- * Verify Mailbox
- * @param string $value
- */
- public static function Checkzip ($STR) {
- if (strlen ($STR)!=6) {
- return false;
- }
- if (substr ($str, 0, 1) ==0) {
- return false;
- }
- return true;
- }
- /**
- * Match Date
- * @param string $value
- */
- public static function Checkdate ($STR) {
- $DATEARR = Explode ("-", $str);
- if (is_numeric ($dateArr [0]) && is_numeric ($DATEARR [1]) && is_numeric ($DATEARR [2])) {
- if ($dateArr [0] >= && $timeArr [0] <= 10000) && ($DATEARR [1] >= 0 && $dateArr [1] < && ($DATEARR [2] >= 0 && $dateArr [2] <= 31))
- return true;
- Else
- return false;
- }
- return false;
- }
- /**
- * Match Time
- * @param string $value
- */
- public static function Checktime ($STR) {
- $TIMEARR = Explode (":", $STR);
- if (is_numeric ($timeArr [0]) && is_numeric ($TIMEARR [1]) && is_numeric ($TIMEARR [2])) {
- if ($timeArr [0] >= 0 && $timeArr [0] <= && ($TIMEARR [1] >= 0 && $timeArr [1] <= 59) && ($TIMEARR [2] >= 0 && $timeArr [2] <= 59))
- return true;
- Else
- return false;
- }
- return false;
- }
- }
Copy Code
|