java常用简单正则表达式写法
邮箱的判断
1 /** 2 * 判断email是否合法 3 */ 4 public static boolean checkLoginEmail(String loginStr) { 5 String regEx = "^([a-z0-9_A-Z]+[-|\\.]?)+[a-z0-9_A-Z]@([a-z0-9_A-Z]+(-[a-z0-9_A-Z]+)?\\.)+[a-zA-Z_]{2,}$"; 6 Pattern p = Pattern.compile(regEx); 7 Matcher m = p.matcher(loginStr); 8 return m.matches();// boolean 9 }
简单格式
public static boolean isKaChao(String kachao){ Pattern p = Pattern.compile("^(0){5}3[0-9]{4}$"); Matcher m = p.matcher(kachao); return m.matches(); }