1. package com.hengxin.qianee.utils;
  2.  
  3. import java.net.InetAddress;
  4.  
  5. public class RegexUtils {
  6.  
  7. /**
  8. * 用户名是否符合规范(^[\u4E00-\u9FA5A-Za-z0-9_]+$)
  9. * @return
  10. */
  11. public static boolean isValidUsername(String username) {
  12. if (username==null || username.trim() == "") {
  13. return false;
  14. }
  15.  
  16. return username.matches("^[\u4E00-\u9FA5A-Za-z0-9_]{2,10}$");
  17. }
  18.  
  19. /**
  20. * 密码是否符合规范([a-zA-Z\d]{6,20})
  21. * @return
  22. */
  23. public static boolean isValidPassword(String password) {
  24. if (null == password) {
  25. return false;
  26. }
  27.  
  28. return password.matches("^([^\\s'‘’]{6,20})$");
  29. }
  30. // public static boolean isValidPassword(String password) {
  31. // if (null == password) {
  32. // return false;
  33. // }
  34. //
  35. // return password.matches("[a-zA-Z\\d]{6,20}");
  36. // }
  37. /**
  38. * 是否有效手机号码
  39. * @param mobileNum
  40. * @return
  41. */
  42. public static boolean isMobileNum(String mobileNum) {
  43. if (null == mobileNum) {
  44. return false;
  45. }
  46.  
  47. return mobileNum.matches("^((13[0-9])|(14[4,7])|(15[^4,\\D])|(17[6-8])|(18[0-9]))(\\d{8})$");
  48. }
  49.  
  50. /**
  51. * 是否有效邮箱
  52. * @param email
  53. * @return
  54. */
  55. public static boolean isEmail(String email) {
  56. if (null == email) {
  57. return false;
  58. }
  59.  
  60. return email.matches("^([a-zA-Z0-9])+([a-zA-Z0-9_.-])+@([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,3}){1,2})$");
  61. }
  62.  
  63. /**
  64. * 是否是QQ邮箱
  65. */
  66. public static boolean isQQEmail(String email){
  67. if(null == email)
  68. return false;
  69.  
  70. return email.matches("^[\\s\\S]*@qq.com$");
  71. }
  72.  
  73. /**
  74. * 是否数字(小数||整数)
  75. * @param number
  76. * @return
  77. */
  78. public static boolean isNumber(String number) {
  79. if (null == number) {
  80. return false;
  81. }
  82.  
  83. return number.matches("^[+-]?(([1-9]{1}\\d*)|([0]{1}))(\\.(\\d)+)?$");
  84. }
  85.  
  86. /**
  87. * 是否整数
  88. * @param number
  89. * @return
  90. */
  91. public static boolean isInt(String number) {
  92. if (null == number) {
  93. return false;
  94. }
  95.  
  96. return number.matches("^[+-]?(([1-9]{1}\\d*)|([0]{1}))$");
  97. }
  98.  
  99. /**
  100. * 是否正整数
  101. * @param number
  102. * @return
  103. */
  104. public static boolean isPositiveInt(String number) {
  105. if (null == number) {
  106. return false;
  107. }
  108.  
  109. return number.matches("^[+-]?(([1-9]{1}\\d*)|([0]{1}))$");
  110. }
  111.  
  112. /**
  113. * 是否日期yyyy-mm-dd(yyyy/mm/dd)
  114. * @param date
  115. * @return
  116. */
  117. public static boolean isDate(String date) {
  118. if (null == date) {
  119. return false;
  120. }
  121. return date.matches("^([1-2]\\d{3})[\\/|\\-](0?[1-9]|10|11|12)[\\/|\\-]([1-2]?[0-9]|0[1-9]|30|31)$");
  122. }
  123.  
  124. /**
  125. * 逗号分隔的正则表达式
  126. * @param str
  127. * @return
  128. */
  129. public static String getCommaSparatedRegex(String str) {
  130. if (str == null) {
  131. return null;
  132. }
  133.  
  134. return "^("+str+")|([\\s\\S]*,"+str+")|("+str+",[\\s\\S]*)|([\\s\\S]*,"+str+",[\\s\\S]*)$";
  135. }
  136.  
  137. /**
  138. * 字符串包含
  139. * @return
  140. */
  141. public static boolean contains(String str, String regex) {
  142. if (str == null || regex == null) {
  143. return false;
  144. }
  145.  
  146. return str.matches(regex);
  147. }
  148.  
  149. /**
  150. * 是否为16,19或者22位银行账号
  151. * @param bankAccount
  152. * @return
  153. */
  154. public static boolean isBankAccount(String bankAccount){
  155. if (null == bankAccount) {
  156. return false;
  157. }
  158.  
  159. return bankAccount.matches("^(\\d{19}|\\d{16}|\\d{22})$");
  160. }
  161.  
  162. /**
  163. * 获取本机IP
  164. * @return
  165. */
  166. public static String getIp(){
  167.  
  168. InetAddress ia=null;
  169. try {
  170. ia=ia.getLocalHost();
  171.  
  172. String localip=ia.getHostAddress();
  173. //String localname=ia.getHostName();
  174. //System.out.println("本机名称:"+ localname);
  175. //System.out.println("本机的ip :"+localip);
  176.  
  177. return localip;
  178. } catch (Exception e) {
  179. e.printStackTrace();
  180. }
  181.  
  182. return "127.0.0.1";
  183. }
  184.  
  185. }

java 后台校验格式的更多相关文章

  1. @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 前台request 获取body的格式是正确的 (2018-03-23 16:44:22) 但是Java 后台却格式化成了yyyy-MM-dd的格式 巨坑(@InitBinder搞得贵)

    最近做项目时,同事写的功能总是格式化时间不正确,Java类属性明明注解了@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")  但就是硬 ...

  2. java后台校验 hibernate validator

    链接 : https://www.cnblogs.com/softidea/p/6044123.html

  3. js前台传数组,java后台接收转list,前后台用正则校验

    前台,传参数时,将数组对象转换成json串,后台java收到后用 JSONArray.fromObject 转成集合. 前台js:var params = {"FileNameList&qu ...

  4. ajax提交数据到java后台,并且返回json格式数据前台接收处理值

    1.前台html页面.有一段代码如下: 账  户:  <input type="text" name="userName" id="userN& ...

  5. fastJson java后台转换json格式数据

    什么事JSON? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Progra ...

  6. fastJson在java后台转换json格式数据探究(二)--处理数组/List/Map

    作者:buster2014 推荐:长安散人 fastJson在java后台转换json格式数据探究(二)--处理数组/List/Map JSON字符串与Java对象的转换 1.将Java对象或Java ...

  7. C#picturebox控件图片以json格式上传java后台保存

    关于winform上传图片到Java后端,保存到数据库,有多种方法,本文主要介绍利用picturebox控件,点击按钮上传图片,将图片转化为base64格式,以json格式上传到Java后台,再从ja ...

  8. java 后台实现ajax post跨域请求传递json格式数据获取json数据问题

    参考大神:http://blog.csdn.net/chunqiuwei/article/details/19924821 java后台: public String ajaxProxy(Intege ...

  9. 如何用CropBox实现头像裁剪并与java后台交互

    如何用CropBox实现头像裁剪并与java后台交互 参考网站:https://developer.mozilla.org/zh-CN/docs/Web/API/Blob 参考: http://blo ...

随机推荐

  1. 嵌入式之Linux系统裁剪和定制---(kernel+busyboxy+dropbear+nginx)

    本文将介绍通过完全手动定制内核,在此基础上添加 busybox ,并实现远程登陆,使裁剪的 linux 能够运行 nginx . 在此之前介绍一下 linux 系统的启动流程. linux系统启动流程 ...

  2. Cheatsheet: 2015 09.01 ~ 09.30

    Web A Guide to Vanilla Ajax Without jQuery Gulp for Beginners A Detailed Walkthrough of ASP.net MVC ...

  3. Android handler 详解(面试百分之100问到)

    handler在Android中被称为“消息处理者”,在多线程中比较常用. handler内部实现原理 handler实现机制:1,Message对象,表示要传递的一个消息,内部使用链表数据结构实现一 ...

  4. Deep Learning 16:用自编码器对数据进行降维_读论文“Reducing the Dimensionality of Data with Neural Networks”的笔记

    前言 论文“Reducing the Dimensionality of Data with Neural Networks”是深度学习鼻祖hinton于2006年发表于<SCIENCE > ...

  5. STL中的查找算法

    STL中有很多算法,这些算法可以用到一个或多个STL容器(因为STL的一个设计思想是将算法和容器进行分离),也可以用到非容器序列比如数组中.众多算法中,查找算法是应用最为普遍的一类. 单个元素查找 1 ...

  6. 如何解决EditText使用时,点击外侧系统键盘不消失的bug

    在使用viewPager和EditText一起使用的时候,突然出现了一个bug,在点击EditText(此EditText是在ViewPager的Fragment中) 我在切换ViewPager的时候 ...

  7. linux笔记:文件系统管理-fdisk分区

    fdisk命令分区过程: 1.添加新硬盘 2.查看新硬盘: fdisk -l 3.使用fdisk命令分区: fdisk 硬盘设备文件名(如:fdisk /dev/sdb) fdisk交互指令说明: 4 ...

  8. 0010 Linux 目录操作命令

    01.更改目录 cd  /  返回根目录 cd ~  返回用户根目录 cd -  返回上个操作目录目录 ,等同于cd $OLDPWD 02.查看工作目录 pwd 03.创建目录 mkdir 目录名 0 ...

  9. 三种JS方法确定元素在数组中的索引值

    第一种:数组遍历 function search(arr,dst){ var i = arr.length; while(i-=1){ if (arr[i] == dst){ return i; } ...

  10. mysql 存储过程简介

    存储过程类似一个存储在数据库的一个数据库脚本.它类似一个方法,可以批量执行一些数据库的操作. 本文编写一个简单的存储过程来快速了解存储过程. 1.因为存储过程类似编程语言的方法,所以方法中可能会用到 ...