java 正则表达式

  1. String num = “(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)”;

  2. String regex = “^” + num + “\\.” + num + “\\.” + num + “\\.” + num + “$”;

  3. return match(regex, str);

  4. }

  5. /**

  6. * 验证网址Url

  7. * @param 待验证的字符串

  8. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  9. */

  10. public static boolean IsUrl(String str)

  11. {

  12. String regex = “http(s)?😕/([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?”;

  13. return match(regex, str);

  14. }

  15. /**

  16. * 验证电话号码

  17. * @param 待验证的字符串

  18. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  19. */

  20. public static boolean IsTelephone(String str)

  21. {

  22. String regex = “^(\\d{3,4}-)?\\d{6,8}$”;

  23. return match(regex, str);

  24. }

  25. /**

  26. * 验证输入密码条件(字符与数据同时出现)

  27. * @param 待验证的字符串

  28. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  29. */

  30. public static boolean IsPassword(String str)

  31. {

  32. String regex = “[A-Za-z]+[0-9]”;

  33. return match(regex, str);

  34. }

  35. /**

  36. * 验证输入密码长度 (6-18位)

  37. * @param 待验证的字符串

  38. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  39. */

  40. public static boolean IsPasswLength(String str)

  41. {

  42. String regex = “^\\d{6,18}$”;

  43. return match(regex, str);

  44. }

  45. /**

  46. * 验证输入邮政编号

  47. * @param 待验证的字符串

  48. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  49. */

  50. public static boolean IsPostalcode(String str)

  51. {

  52. String regex = “^\\d{6}$”;

  53. return match(regex, str);

  54. }

  55. /**

  56. * 验证输入手机号码

  57. * @param 待验证的字符串

  58. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  59. */

  60. public static boolean IsHandset(String str)

  61. {

  62. String regex = “^[1]+[3,5]+\\d{9}$”;

  63. return match(regex, str);

  64. }

  65. /**

  66. * 验证输入身份证号

  67. * @param 待验证的字符串

  68. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  69. */

  70. public static boolean IsIDcard(String str)

  71. {

  72. String regex = “(^\\d{18}KaTeX parse error: Got function '\\' with no arguments as superscript at position 5: )|(^\̲\̲\\d{15})”;

  73. return match(regex, str);

  74. }

  75. /**

  76. * 验证输入两位小数

  77. * @param 待验证的字符串

  78. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  79. */

  80. public static boolean IsDecimal(String str)

  81. {

  82. String regex = “^[0-9]+(.[0-9]{2})?$”;

  83. return match(regex, str);

  84. }

  85. /**

  86. * 验证输入一年的12个月

  87. * @param 待验证的字符串

  88. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  89. */

  90. public static boolean IsMonth(String str)

  91. {

  92. String regex = “^(0?[[1-9]|1[0-2])$”;

  93. return match(regex, str);

  94. }

  95. /**

  96. * 验证输入一个月的31天

  97. * @param 待验证的字符串

  98. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  99. */

  100. public static boolean IsDay(String str)

  101. {

  102. String regex = “^((0?[1-9])|((1|2)[0-9])|30|31)$”;

  103. return match(regex, str);

  104. }

  105. /**

  106. * 验证日期时间

  107. * @param 待验证的字符串

  108. * @return 如果是符合网址格式的字符串,返回 true ,否则为 false 

  109. */

  110. public static boolean isDate(String str)

  111. {

  112. //严格验证时间格式的(匹配[2002-01-31], [1997-04-30], [2004-01-01])不匹配([2002-01-32], [2003-02-29], [04-01-01])

  113. //        String regex = “^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((01,3-9])|(1[0-2]))-(29|30)))))$”;

  114. //没加时间验证的YYYY-MM-DD

  115. //        String regex = “^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$”;

  116. //加了时间验证的YYYY-MM-DD 00:00:00

  117. String regex = “^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\\d):[0-5]?\\d:[0-5]?\\d$”;

  118. return match(regex, str);

  119. }

  120. /**

  121. * 验证数字输入

  122. * @param 待验证的字符串

  123. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  124. */

  125. public static boolean IsNumber(String str)

  126. {

  127. String regex = “^[0-9]*$”;

  128. return match(regex, str);

  129. }

  130. /**

  131. * 验证非零的正整数

  132. * @param 待验证的字符串

  133. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  134. */

  135. public static boolean IsIntNumber(String str)

  136. {

  137. String regex = “^\\+?[1-9][0-9]*$”;

  138. return match(regex, str);

  139. }

  140. /**

  141. * 验证大写字母

  142. * @param 待验证的字符串

  143. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  144. */

  145. public static boolean IsUpChar(String str)

  146. {

  147. String regex = “^[A-Z]+$”;

  148. return match(regex, str);

  149. }

  150. /**

  151. * 验证小写字母

  152. * @param 待验证的字符串

  153. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  154. */

  155. public static boolean IsLowChar(String str)

  156. {

  157. String regex = “^[a-z]+$”;

  158. return match(regex, str);

  159. }

  160. /**

  161. * 验证验证输入字母

  162. * @param 待验证的字符串

  163. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  164. */

  165. public static boolean IsLetter(String str)

  166. {

  167. String regex = “^[A-Za-z]+$”;

  168. return match(regex, str);

  169. }

  170. /**

  171. * 验证验证输入汉字

  172. * @param 待验证的字符串

  173. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  174. */

  175. public static boolean IsChinese(String str)

  176. {

  177. String regex = “^[\u4e00-\u9fa5],{0,}$”;

  178. return match(regex, str);

  179. }

  180. /**

  181. * 验证验证输入字符串

  182. * @param 待验证的字符串

  183. * @return 如果是符合格式的字符串,返回 true ,否则为 false 

  184. */

  185. public static boolean IsLength(String str)

  186. {

  187. String regex = “^.{8,}$”;

最后

由于篇幅原因,就不多做展示了

了解详情https://docs.qq.com/doc/DSmxTbFJ1cmN1R2dB
th(String str)

  1. {

  2. String regex = “^.{8,}$”;

最后

[外链图片转存中…(img-s7qJluR1-1724237459395)]

[外链图片转存中…(img-83yNLe54-1724237459396)]

[外链图片转存中…(img-9QhbOS6H-1724237459396)]

[外链图片转存中…(img-tKEPYImr-1724237459396)]

[外链图片转存中…(img-x7oZMhVA-1724237459397)]

[外链图片转存中…(img-utvu9ohQ-1724237459397)]

由于篇幅原因,就不多做展示了

了解详情https://docs.qq.com/doc/DSmxTbFJ1cmN1R2dB

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值