常用正则表达式

1.判断一个字符串中是否包含日期 yyyy-MM-dd

Pattern pattern = Pattern.compile("\\d{4}\\-(0?[1-9]|[1][012])\\-(0?[1-9]|[12][0-9]|3[01])");
Matcher matcher = pattern.matcher(date);

 

2.是否包含手机号

Pattern mobilePattern = Pattern.compile("^((13[0-9])|(14[5|7])|(15[^4,\\D])|(18[0-9])|(17[0-9])|(166)|(19[8|9]))\\d{8}$");
Matcher mobileMatcher = mobilePattern.matcher(mobile.trim());

 

3.是否包含邮箱

Pattern emailPattern = Pattern.compile("^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
Matcher emailMatcher = emailPattern.matcher(email.trim());

 

posted on 2019-10-28 09:42  指尖,写不尽  阅读(251)  评论(2编辑  收藏  举报

导航