public static void main(String[] args) {
// 11位手机号 13 15 17 18 14 必须9位纯数字
Pattern p=Pattern.compile("^1(3|5|7|8|4)\\d{9}$");
Matcher m=p.matcher("18993109776");
boolean b=m.matches();
System.out.println(b);
//验证身份证 最后 X x 结尾 18位
Pattern x = Pattern.compile("^\\d{17}(x|X|\\d)$");
Matcher q = p.matcher("362204199208270511");
boolean w = m.matches();
System.out.println(b);
//验证邮箱
Pattern o = Pattern.compile("^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$");
Matcher v = p.matcher("782659445@qq.net");
boolean u = m.matches();
System.out.println(b);
}
正则表达式的用法
最新推荐文章于 2022-03-30 19:58:16 发布