|
|
@@ -0,0 +1,88 @@
|
|
|
+package com.cyksj.common.util;
|
|
|
+
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 正则校验
|
|
|
+ *
|
|
|
+ * @author valor
|
|
|
+ * @date 2018/10/8 01:25
|
|
|
+ */
|
|
|
+public class ValidatorUtil {
|
|
|
+
|
|
|
+ private ValidatorUtil() { }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 正则表达式:验证手机号(精确)
|
|
|
+ * <p>移动:134(0-8)、135、136、137、138、139、147、150、151、152、157、158、159、178、182、183、184、187、188、198</p>
|
|
|
+ * <p>联通:130、131、132、145、155、156、175、176、185、186、166</p>
|
|
|
+ * <p>电信:133、153、173、177、180、181、189、199</p>
|
|
|
+ * <p>全球星:1349</p>
|
|
|
+ * <p>虚拟运营商:170</p>
|
|
|
+ */
|
|
|
+ private static final Pattern P_MOBILE = Pattern.compile("(?:0|86|\\+86)?1[3456789]\\d{9}");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 正则表达式:验证身份证
|
|
|
+ */
|
|
|
+ private static final Pattern P_ID_CARD = Pattern.compile("^[1-9]\\d{5}(18|19|20)\\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\\d{3}[0-9X]$");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 正则表达式: 中文名
|
|
|
+ */
|
|
|
+ private static final Pattern P_CHINESE_NAME = Pattern.compile("^([\\u4e00-\\u9fa5\\·]{2,16})$");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 正则表达式:数字
|
|
|
+ */
|
|
|
+ private static final Pattern P_NUM = Pattern.compile("^[0-9]\\d{9,29}$");
|
|
|
+
|
|
|
+ private static final Pattern EN_NUM = Pattern.compile("^[A-Za-z0-9]+$");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验手机号
|
|
|
+ *
|
|
|
+ * @param mobile
|
|
|
+ * @return 校验通过返回true,否则返回false
|
|
|
+ */
|
|
|
+ public static boolean isMobile(String mobile) {
|
|
|
+ return P_MOBILE.matcher(mobile).matches();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验身份证
|
|
|
+ *
|
|
|
+ * @param idCard
|
|
|
+ * @return 校验通过返回true,否则返回false
|
|
|
+ */
|
|
|
+ public static boolean isIDCard(String idCard) {
|
|
|
+ return P_ID_CARD.matcher(idCard).matches();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验中文名
|
|
|
+ *
|
|
|
+ * @param name
|
|
|
+ * @return 校验通过返回true,否则返回false
|
|
|
+ */
|
|
|
+ public static boolean isChineseName(String name) {
|
|
|
+ return P_CHINESE_NAME.matcher(name).matches();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验银行卡号
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return 校验通过返回true,否则返回false
|
|
|
+ */
|
|
|
+ public static boolean isNum(String id){
|
|
|
+ return P_NUM.matcher(id).matches();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 英文+数字
|
|
|
+ */
|
|
|
+ public static boolean isEnNum(String str){
|
|
|
+ return EN_NUM.matcher(str).matches();
|
|
|
+ }
|
|
|
+}
|