Andriod 正則表達式(持續添加)



//手機號碼

public static boolean isMobileNo(String mobiles) {
  Pattern p = Pattern
    .compile("^(\\+?)(86)?((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
  Matcher m = p.matcher(mobiles);
  return m.matches();
 }


//郵件

 public static boolean isEmail(String email) {
  Pattern p = Pattern
    .compile("^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$");
  Matcher m = p.matcher(email);
  return m.matches();
 }


//只允許中英文、數字、下劃線(_)和點號(.)

 public static boolean isOK(String str) {
  Pattern p = Pattern
    .compile[“\\u4E00-\\u9FBF\\w.]+");
  Matcher m = p.matcher(str);
  return m.matches();
 }



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章