惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - Valen

命令方式启动SQL服务 tomcat中显示文件目录 equals中NullPointerException问题解决 - Valen - 博客园 JSTL与EL表达式简单应用 - Valen - 博客园 Jsp重定向forward和sendRedirect的区别 Java,Hibernate,Sql之间数据类型对应表 Jsp中EL表达式不能显示的解决方法 JAVA读取Properties的六种方法 Jsp中errorPage使用及web.xml配置 - Valen - 博客园 Install JSEclipse Method 备份你的手机通讯录到网络吧! vsftpd 配置 解决fedora11 root用户登录问题 Windows与Vmware下的Linux文件共享方法 Windows Live 设置 雷人签名 ob_start 用法 分页算法(1) 小沈阳 "不差钱" 改编版
转:Java调用正则表达式 - Valen - 博客园
Valen · 2009-10-01 · via 博客园 - Valen

package com.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexBean {
        Pattern p = null;
        Matcher m = null;
        String str1 = "^[0-9]{1,20}$"; //校验是否全由数字组成
        String str2 = "^[a-zA-Z]{1}([a-zA-Z0-9]|[._]){4,19}$";
        //校验登录名:只能输入5-20个以字母开头、可带数字、“_”、“.”的字串
        //String str20="^([0-9]{1}[.]{0,1}[0-9]*)$";
        String str3 = "^(http://www.cnblogs.com/iamvalen/admin/file://w)%7b6,20%7d$/"; //校验密码:只能输入6-20个字母、数字、下划线
        String str4 = "^[+]{0,1}(http://www.cnblogs.com/iamvalen/admin/file://d)%7b1,3/}[ ]?([-]?((http://www.cnblogs.com/iamvalen/admin/file://d/)|[ ]){1,12})+$";
        //校验普通电话、传真号码:可以“+”开头,除数字外,可含有“-”
        String str5 = "^[+]{0,1}(http://www.cnblogs.com/iamvalen/admin/file://d)%7b1,3/}[ ]?([-]?((http://www.cnblogs.com/iamvalen/admin/file://d/)|[ ]){1,12})+$"; //校验手机号码
        String str6 = "^[a-zA-Z0-9 ]{3,6}$"; //校验邮政编码
        String str7 = "^[0-9.]{1,20}$"; //ip
        String str8 = "^\\d+$"; //非负整数
        String str9 = "^[0-9]*[1-9][0-9]*$"; //正整数
        String str10 = "^[A-Za-z]+$"; //由26个英文字母组成的字符串
        String str11 = "^\\w+$"; //由数字、26个英文字母或者下划线组成的字符串
        String str12 = "^[\\w-]+(http://www.cnblogs.com/iamvalen/admin/file://.[//w-]+)*@[//w-]+(//.[//w-]+)+$"; //email
        String str13 = "^[a-zA-z]+://(http://www.cnblogs.com/iamvalen/admin/file://w+(-//w+)*)(//.(//w+(-//w+)*))*(//?\\S*)?$";
        //url
        String str14 = "[0-9]{4}\\-[0-9]{1,2}\\-[0-9]{1,2}";
        String str15 =
                "^((((19|20)(([02468][048])|([13579][26]))\\-02\\-29))|((20[0-9][0-9])|(19[0-9][0-9]))\\-((((0[1-9])|(1[0-2]))\\-((0[1-9])|(1\\d)|(2[0-8])))|((((0[13578])|(1[02]))\\-31)|(((01,3-9])|(1[0-2]))\\-(29|30)))))$";
                //date 如2004-06-06,非常精确,如2004-06-32可以查出非法!!
        String str16 =
                "^(http://www.cnblogs.com/iamvalen/admin/file://d%7b4%7d)//-(//d%7B2%7D)//-(//d%7B2}) (http://www.cnblogs.com/iamvalen/admin/file://d%7b2%7d):(//d%7B2%7D):(//d%7B2%7D)$";
                //date and time 如2004-11-12 12:10:16
        String str17 = "^([\u4e00-\u9fa5]*)";//汉字
        public RegexBean() {}
       
        public boolean isDate(String str) {
                p = Pattern.compile(str15);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        /*public boolean isfloat(String str)
        {
            p=Pattern.compile(str20);
            m=p.matcher(str);
            boolean b=m.matches();
            if(b)
                return true;
            else
                return false;
        }*/
        public boolean isEmail(String str) {
                p = Pattern.compile(str12);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isDateAndTime(String str) {
                p = Pattern.compile(str16);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isUserName(String str) {
                p = Pattern.compile(str2);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isPassword(String str) {
                p = Pattern.compile(str3);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isPhone(String str) {
                p = Pattern.compile(str4);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isMobile(String str) {
                p = Pattern.compile(str5);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isPost(String str) {
                p = Pattern.compile(str6);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isIP(String str) {
                p = Pattern.compile(str7);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isChinese(String str) {
                p = Pattern.compile(str17);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isURL(String str) {
                p = Pattern.compile(str13);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public boolean isDigit(String str) {
                p = Pattern.compile(str1);
                m = p.matcher(str);
                boolean b = m.matches();
                if (b)
                        return true;
                else
                        return false;
        }
        public static void main(String[] args) {
                RegexBean bb = new RegexBean();
                String str = "2005-11-01";
                System.out.println(bb.isDate(str));
                //String f="38700000000";
                //System.out.println(bb.isMobile(f));
        }
}