Validation.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/9/7
  6. * Time: 17:55
  7. */
  8. namespace App\Commons\Controller;
  9. class Validation
  10. {
  11. public static function isUser($data, $config = ['cn' => 0, '_' => 1])
  12. {
  13. $parten = "/^([\x{4e00}-\x{9fa5}\w])+([\x{4e00}-\x{9fa5}\w]\d_)?$/u";
  14. return preg_match($parten, $data);
  15. }
  16. public static function isChinease($data)
  17. {
  18. $patern = "/^[\x{4e00}-\x{9fa5}]+$/u";
  19. return preg_match($patern, $data);
  20. }
  21. public static function isWords($data)
  22. {
  23. $patern = "/^[a-z_A-Z]+$/";
  24. return preg_match($patern, $data);
  25. }
  26. public static function isWordWithNumberEnd($data)
  27. {
  28. $patern = "/^\w+[\-]?[_]?[\w\d]?$/";
  29. return preg_match($patern, $data);
  30. }
  31. public static function isEmail($data)
  32. {
  33. $patern='/^[\d\w]+([_]?[\-]?[\.]?[\d\w]+)?@[\d\w]+[\.]+[\w]{2,4}/';
  34. return preg_match($patern,$data);
  35. }
  36. public static function isFloat($data)
  37. {
  38. $patern = '/^[\d]+\.?\d+$/';
  39. return preg_match($patern, $data);
  40. }
  41. }