java regular expression to validate email, phone number

/**
  * Verify email address is correct
  * @param email
  * @return
  */
 public static boolean checkEmail(String email){
  boolean flag = false;
  try{
   Check string = "^ ([a-Z0-9-Z] + [- | \\.]?) + [A-Z0-9-Z] @ ([a-Z0-9-Z] + (- [ a-Z0-9-Z] +)? \\.) + [a-zA-Z] {2} $ " ;
   Pattern regex = Pattern.compile(check);
   Matches matches = regex.matcher (email);
   flag = matcher.matches();
  }catch(Exception e){
   Log.error ( "email address validation error" , E);
   flag = false;
  }
  
  return flag;
 }
 /**
  * Verify phone number
  * @param mobiles
  * @return
  */
 public static boolean isMobileNO(String mobiles){
  boolean flag = false;
  try{
   Pattern p = Pattern.compile("^((13[0-9])|(15[^4,\\D])|(18[0,5-9]))\\d{8}$");
   Matcher m = p.matcher (mobile);
   flag = m.matches();
  }catch(Exception e){
   Log.error ( "verify the phone number wrong" , E);
   flag = false;
  }
  return flag;
 }

Reproduced in: https: //www.iteye.com/blog/zjf201172653-2005363

Guess you like

Origin www.cnblogs.com/it-deepinmind/p/11791007.html