Validate.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace PhpLife\Frame\Helper;
  3. /**
  4. * 校验类, 尚未严格验证
  5. * @package PhpLife\Frame\Helper
  6. */
  7. class Validate extends \PhpLife\Frame\Helper
  8. {
  9. public static function isUrl($url)
  10. {
  11. $regex = '/((https?|ftp|news):\/\/)?([a-z]*([a-z0-9\-]*[\.。])+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel)|(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-z][a-z0-9_]*)?/i';
  12. return preg_match($regex, $url);
  13. }
  14. public static function isEmail($email)
  15. {
  16. return preg_match("/^(\w+((-\w+)|(\w.\w+))*)\@(\w+((\.|-)\w+)*\.\w+$)/", $email);
  17. }
  18. public static function isMobile($phone)
  19. {
  20. return preg_match("/^1\d{10}$/", $phone);
  21. }
  22. public static function isCountryMobile($phone)
  23. {
  24. return preg_match("/^[1-9]{1}\d{3,14}$/", $phone);
  25. }
  26. public static function isDate($str)
  27. {
  28. if (!preg_match("/^\d{4}-\d{2}-\d{2}$/", $str)) {
  29. return FALSE;
  30. }
  31. $stamp = strtotime($str);
  32. if (!is_numeric($stamp)) {
  33. return FALSE;
  34. }
  35. if (checkdate(date('m', $stamp), date('d', $stamp), date('Y', $stamp))) {
  36. return TRUE;
  37. }
  38. return FALSE;
  39. }
  40. public static function isIntval($mixed)
  41. {
  42. return (preg_match('/^\d*$/', $mixed) == 1);
  43. }
  44. }