|
@@ -0,0 +1,131 @@
|
|
|
+package com.flyer.foster.pojo;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 表单验证工具类
|
|
|
+ * @author 86137
|
|
|
+ *
|
|
|
+ */
|
|
|
+public class CheckUtil {
|
|
|
+
|
|
|
+ public static String key="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9";
|
|
|
+ public static String feiniaoKey="eyJzdWIiOiIxMjM0NTY3ODkwIiwibmF";
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * key是否正确
|
|
|
+ * @param key1
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean isKey(String key1){
|
|
|
+ if(key.equals(key1)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * key是否正确
|
|
|
+ * @param key1
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean isFeiniaoKey(String key1){
|
|
|
+ if(feiniaoKey.equals(key1)){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isDate(String dateStr){
|
|
|
+ try {
|
|
|
+ if(LocalDate.parse(dateStr) != null){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }catch (RuntimeException e){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 验证是不是数字
|
|
|
+ * @param text
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean isNumber(String text) {
|
|
|
+ if(text == null || text.length() == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int i = text.length() - 1;
|
|
|
+ while(i > -1) {
|
|
|
+ int c = text.charAt(i);
|
|
|
+ if(c < '0' || c > '9' ) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ i--;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.out.println();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证不为null 或 "" 或 " "
|
|
|
+ * @param text
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static boolean notNull(String text) {
|
|
|
+ if(text == null || text.trim().equals("")) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isPhone(String phone) {
|
|
|
+ String regex = "^((13[0-9])|(14[0-9])|(15([0-9]))|(16([0-9]))|(17[0-9])|(18[0-9])|(19[0-9]))\\d{8}$";
|
|
|
+ if (phone.length() != 11) {
|
|
|
+// System.out.println("手机号应为11位数");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Pattern p = Pattern.compile(regex);
|
|
|
+ Matcher m = p.matcher(phone);
|
|
|
+ boolean isMatch = m.matches();
|
|
|
+ if (isMatch) {
|
|
|
+// System.out.println("您的手机号" + phone + "是正确格式@——@");
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+// System.out.println("您的手机号" + phone + "是错误格式!!!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean isEmail(String email) {
|
|
|
+ String regex = "^[a-z0-9_\\+-]+(\\.[a-z0-9_\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$";
|
|
|
+ Pattern p = Pattern.compile(regex);
|
|
|
+ Matcher m = p.matcher(email);
|
|
|
+ boolean isMatch = m.matches();
|
|
|
+ if (isMatch) {
|
|
|
+// System.out.println("您的手机号" + phone + "是正确格式@——@");
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+// System.out.println("您的手机号" + phone + "是错误格式!!!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean contains(String[] array, String target) {
|
|
|
+ for (int i = 0; i < array.length; i++) {
|
|
|
+ if (array[i].equals(target)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|