Validation.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Sports\Controller;
  3. /**
  4. * Class Validation
  5. * @package App\Sports\Controller
  6. * 验证器
  7. */
  8. class Validation
  9. {
  10. public static function isChinease($data)
  11. {
  12. $patern = "/^[\x{4e00}-\x{9fa5}]+$/u";
  13. return preg_match($patern, $data);
  14. }
  15. public static function isWords($data)
  16. {
  17. $patern = "/^[a-z_A-Z]+$/";
  18. return preg_match($patern, $data);
  19. }
  20. public static function isWordWithNumberEnd($data)
  21. {
  22. $patern = "/^\w+[\-]?[_]?[\w\d]?$/";
  23. return preg_match($patern, $data);
  24. }
  25. public static function isEmail($data)
  26. {
  27. $patern='/^[\d\w]+([_]?[\-]?[\.]?[\d\w]+)?@[\d\w]+[\.]+[\w]{2,4}/';
  28. return preg_match($patern,$data);
  29. }
  30. public static function isFloat($data)
  31. {
  32. $patern = '/^[\d]+\.?\d+$/';
  33. return preg_match($patern, $data);
  34. }
  35. /**
  36. * @param $data
  37. * @return false|int
  38. * 验证账号规则:字母开头,允许5-16字节,允许字母数字下划线
  39. */
  40. public static function isAccount($data){
  41. $patern = '/[a-zA-Z][a-zA-Z0-9_]{4,15}$/';
  42. return preg_match($patern, $data);
  43. }
  44. /**
  45. * @param $data
  46. * @return false|int
  47. * 验证密码 以字母开头,长度在6~18之间,只能包含字母、数字和下划线
  48. */
  49. public static function isPassword($data){
  50. $patern = '/^[a-zA-Z]\w{5,17}$/';
  51. return preg_match($patern, $data);
  52. }
  53. /**
  54. * @param $data
  55. * @return false|int
  56. * 验证密保问题答案 中文字母数字
  57. */
  58. public static function isAnswer($data){
  59. $patern = '/^[\u4e00-\u9fa5a-zA-Z-z0-9]+$/';
  60. return preg_match($patern, $data);
  61. }
  62. /**
  63. * @param $data
  64. * @return false|int
  65. * 验证提款密码 以字母开头,长度在6~18之间,只能包含字母、数字和下划线
  66. */
  67. public static function isWmpassword($data){
  68. $patern = '/^[a-zA-Z]\w{5,17}$/';
  69. return preg_match($patern, $data);
  70. }
  71. }