Regexp.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wangyachao
  5. * Time: 15:15
  6. */
  7. namespace common\helpers;
  8. class Regexp {
  9. //put your code here
  10. /**
  11. * 验证真实姓名
  12. */
  13. public static $realname = '/^[A-Za-z0-9\\u4e00-\\u9fa5]+$/';
  14. /**
  15. * 浮点数
  16. */
  17. public static $decmal = "/^([+-]?)\\d*\\.\\d+$/";
  18. /**
  19. * 正浮点数
  20. */
  21. public static $decmal1 = "/^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$/";
  22. /**
  23. * 负浮点数
  24. */
  25. public static $decmal2 = "/^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)$/";
  26. /**
  27. * 浮点数
  28. */
  29. public static $decmal3 = "/^-?([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0)$/";
  30. /**
  31. * 非负浮点数(正浮点数 + 0)
  32. */
  33. public static $decmal4 = "/^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0$";
  34. /**
  35. * 非正浮点数(负浮点数 + 0)
  36. */
  37. public static $decmal5 = "/^(-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*))|0?.0+|0$/";
  38. /**
  39. * 整数
  40. */
  41. public static $intege = "/^-?[1-9]\\d*$/";
  42. /**
  43. * 正整数
  44. */
  45. public static $intege1 = "/^[1-9]\\d*$/";
  46. /*
  47. * 负整数
  48. */
  49. public static $intege2 = "/^-[1-9]\\d*$/";
  50. /**
  51. * 数字
  52. */
  53. public static $num = "/^([+-]?)\\d*\\.?\\d+$/";
  54. /**
  55. * 正数(正整数 + 0)
  56. */
  57. public static $num1 = "/^[1-9]\\d*|0$/";
  58. /**
  59. * 负数(负整数 + 0)
  60. */
  61. public static $num2 = "/^-[1-9]\\d*|0$/";
  62. /**
  63. * 仅ACSII字符
  64. */
  65. public static $ascii = "/^[\\x00-\\xFF]+$/";
  66. /**
  67. * 仅中文
  68. */
  69. public static $chinese = "/^[\\u4e00-\\u9fa5]+$/";
  70. /**
  71. * 颜色
  72. */
  73. public static $color = "/^[a-fA-F0-9]{6}$/";
  74. /**
  75. * 日期
  76. */
  77. public static $date = "/^\\d{4}(\\-|\\/|\.)\\d{1,2}\\1\\d{1,2}$/";
  78. /**
  79. * 邮件
  80. */
  81. public static $email = "/^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$/";
  82. /**
  83. * 身份证
  84. */
  85. public static $idcard = "/^[1-9]([0-9]{14}|[0-9]{17}|[0-9]{16}([0-9]|X|x))$/";
  86. /**
  87. * ip地址
  88. */
  89. public static $ip4 = "/^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)$/";
  90. /**
  91. * 字母
  92. */
  93. public static $letter = "/^[A-Za-z]+$/";
  94. /**
  95. * 小写字母
  96. */
  97. public static $letter_l = "/^[a-z]+$/";
  98. /**
  99. * 大写字母
  100. */
  101. public static $letter_u = "/^[A-Z]+$/";
  102. /**
  103. * 手机
  104. */
  105. public static $mobile = '/(13|14|15|17|18)[0-9]{9}$/';
  106. /**
  107. * 电话或者手机
  108. * @var string
  109. */
  110. public static $telormobile = '/^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$/';
  111. /**
  112. * 电话号
  113. */
  114. public static $tel = "/(^(86)\-(0\d{2,3})\-(\d{7,8})\-(\d{1,4})$)|(^0(\d{2,3})\-(\d{7,8})$)|(^0(\d{2,3})\-(\d{7,8})\-(\d{1,4})$)|(^(86)\-(\d{3,4})\-(\d{7,8})$)/";
  115. /**
  116. * 非空
  117. */
  118. public static $notempty = "/^\\S+$/";
  119. /**
  120. * 密码
  121. */
  122. public static $password = "/^[A-Za-z0-9_-]+$/";
  123. /**
  124. * 图片
  125. */
  126. public static $picture = "(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$/";
  127. /*
  128. * QQ号码
  129. */
  130. public static $qq = "/^[1-9]*[1-9][0-9]*$/";
  131. /**
  132. * 压缩文件
  133. */
  134. public static $rar = "(.*)\\.(rar|zip|7zip|tgz)$/";
  135. /**
  136. * url
  137. */
  138. public static $url = "^http[s]? = \\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?$/";
  139. /**
  140. * 用户名
  141. */
  142. public static $username = "/^[A-Za-z0-9_\\-\\u4e00-\\u9fa5]+$/";
  143. /**
  144. * 邮编
  145. */
  146. public static $zipcode = "/^\\d{6}$/";
  147. }