前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >正则判断工具类

正则判断工具类

作者头像
用户1220053
发布2018-02-09 11:49:19
1.6K0
发布2018-02-09 11:49:19
举报
文章被收录于专栏:DT乱“码”DT乱“码”
代码语言:js
复制
package com.gulf.utils;
import java.text.ParseException;
 import java.text.SimpleDateFormat;
/**
  * 正则判断工具类
  * 
  * @author gulf 2016-08-12
  */
 public class RegularUtil {
     /**
      * 判断是否为数字
      * 
      * @param param
      * @return
      */
     public static boolean isDigit(String param) {
         if (param.matches("[0-9]+")) {
             return true;
         }
         return false;
     }
    /**
      * 判断是否为车牌号码
      * 
      * @param param
      * @return
      */
     public static boolean isVehiclePlate(String param) {
         if ((param.matches("^(([\u4e00-\u9fa5]{1})|([A-Z]{1}))[A-Z]{1}[A-Z0-9]{4}(([\u4e00-\u9fa5]{1})|([A-Z0-9]{1}))$")
                 || param.matches("^WJ[0-9]{2}(([\u4e00-\u9fa5]{1})|([0-9]{1})[0-9]{4})$"))
                 && param.matches("^([\u4e00-\u9fa5]*[a-zA-Z0-9]+){6,}$") && param.matches("^.{3}((?!.*O)(?!.*I)).*$")) {
             return true;
         }
         return false;
     }
    /**
      * 整数最多十位,小数最多两位
      * 
      * @param param
      * @return
      */
     public static boolean isNumber12_2(String param) {
         if (param.matches("^(([1-9]\\d{0,9})|0)(\\.\\d{1,2})?$")) {
             return true;
         }
         return false;
     }
 
     /**
      * 整数最多8位,小数最多两位
      * 
      * @param param
      * @return
      */
     public static boolean isNumber10_2(String param) {
         if (param.matches("^(([1-9]\\d{0,7})|0)(\\.\\d{1,2})?$")) {
             return true;
         }
         return false;
     }
    /**
      * 判断是否为手机号
      * 
      * @param param
      * @return
      */
     public static boolean isMobile(String param) {
         if (param.matches("^((1[3,5,8][0-9])|(14[5,7])|(17[0,6,7,8]))\\d{8}$")) {
             return true;
         }
         return false;
     }
    /**
      * 判断是否为邮政编码
      * 
      * @param param
      * @return
      */
     public static boolean isZipCode(String param) {
         if (param.matches("^[0-9]{6}$")) {
             return true;
         }
         return false;
     }
    /**
      * 判断是否为电子邮箱
      * 
      * @param param
      * @return
      */
     public static boolean isEmail(String param) {
         if (param.matches("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*")) {
             return true;
         }
         return false;
     }
    /**
      * 判断是否为车辆识别代码(车架号)
      * 
      * @param param
      * @return
      */
     public static boolean isIdentificationCode(String param) {
         if (param.matches("^[A-Z0-9]{6,17}$")) {
             return true;
         }
         return false;
     }
    /**
      * 判断是否为发动机号
      * 
      * @param param
      * @return
      */
     public static boolean isVehicleEngineNo(String param) {
         if (param.matches("^[A-Z0-9]+$")) {
             return true;
         }
         return false;
     }
    /**
      * 判断是不是金额
      * 
      * @param param
      * @return
      */
     public static boolean isMoney(String param) {
         if (param.matches("^(([1-9]\\d{0,9})|0)(\\.\\d{1,2})?$")) {
             return true;
         }
         return false;
     }
 
    /**
      * 格式是yyyy/MM/dd HH:mm:ss
      * @param param
      * @return
      * @return boolean
      */
     public static boolean isValidDate(String param) {
         boolean convertSuccess = true;
         // 指定日期格式为四位年/两位月份/两位日期,注意yyyy/MM/dd区分大小写;
         SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
         // 设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期
         try {
             format.setLenient(false);
             format.parse(param);
         } catch (ParseException e) {
             convertSuccess = false;
         }
         return convertSuccess;
     }
 
     /**
      * 格式是yyyy-MM-dd
      * @param param
      * @return
      * @return boolean
      */
     public static boolean isValidDay(String param) {
         boolean convertSuccess = true;
         // yyyy-MM-dd
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
         // 设置lenient为false. 否则SimpleDateFormat会比较宽松地验证日期
         try {
             format.setLenient(false);
             format.parse(param);
         } catch (ParseException e) {
             convertSuccess = false;
         }
         return convertSuccess;
     }
    public static void main(String[] args) {
         // test
         // System.out.println(RegularUtil.isDigit("1")+"");
         // System.out.println(RegularUtil.isVehiclePlate("粤a12345")+"");
         // System.out.println(RegularUtil.isNumber12_2("1234567811.11")+"");
         // System.out.println(RegularUtil.isZipCode("555555")+"");
         // System.out.println(RegularUtil.isEmail("5555551111111111111111111111111111111@163.com")+"");
         // System.out.println(RegularUtil.isMobile("13333333333")+"");
         // System.out.println(RegularUtil.isIdentificationCode("111111")+"");
         // System.out.println(RegularUtil.isVehicleEngineNo("234")+"");
         // System.out.println(RegularUtil.isMoney("aaa")+"");
         System.out.println(RegularUtil.isNumber10_2("2345089.11")+"");
     }
 }
 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档