• 常见正则表达式判断


    import java.util.regex.Pattern;
    import org.apache.commons.lang.StringUtils;
    
    public class RegexTool {
        // 日期表达式
        public static final String REG_EXT = "^([1-9]\d{3})((0[1-9])|(1[0-2]))((0[1-9])|([1-2][0-9])|(3[0-1]))(([0-1][0-9])|(2[0-3]))([0-5][0-9])([0-5][0-9])$";
        // 手机表达式
        public static final String REG_PHONE = "^(13\d{9})|(15[0-35-9]\d{8})|(18[05-9]\d{8})$";
        // 昵称表达式
        public static final String REG_NICKNAME = "^[a-zA-Z0-9]{4,16}$";
        // 邮箱表达式
        public static final String REG_EMAIL = "^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$";
        // MD5值格式
        public static final String REG_MD = "^[a-zA-Z0-9]{32}$";
        // 中文真实姓名格式
        public static final String REG_REALNAME = "^[u4E00-u9FA5]{2,8}$";
        // 数字格式
        public static final String REG_NUMBER = "^\d+$";
        // 时间戳格式
        public static final String REG_TIMESTAMP = "^\d{13}$";
        // IP格式
        public static final String REG_IP = "^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$";
        // MAC地址格式
        public static final String REG_MAC = "^[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}-[0-9A-Fa-f]{2}$";
    
        public static boolean check(String regex, String input) {
            if (StringUtils.isNotEmpty(regex) && StringUtils.isNotEmpty(input)){
                return Pattern.matches(regex, input);
            }
            return false;
        }
    }
  • 相关阅读:
    前后端反爬虫的一些奇怪姿势【转载】
    Scrapy 中常用的中间件和管道组件
    Jquery各个版本的区别
    userAgent
    操作系统
    手机类别
    移动端设备UA检测
    iPhone6的CSS3媒体查询
    所有设备的CSS像素
    解读所有设备的css像素的网站
  • 原文地址:https://www.cnblogs.com/shiyuelp/p/7063752.html
Copyright © 2020-2023  润新知