CommonService.php 641 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Services\Api;
  3. class CommonService
  4. {
  5. /**
  6. * 验证邮箱是否正确
  7. * @param INT $email
  8. */
  9. public static function is_email($email) {
  10. if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
  11. return false;
  12. }
  13. return true;
  14. }
  15. /**
  16. * 验证手机号是否正确
  17. * @param INT $mobile
  18. */
  19. public static function is_mobile($mobile) {
  20. if (!is_numeric($mobile)) {
  21. return false;
  22. }
  23. return preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $mobile) ? true : false;
  24. }
  25. }