Android開發工具 + 生產力類(小方法)

來源:互聯網
上載者:User

標籤:android開發   正則   工具類   

  1,郵箱地址只展示部分,只展示@前面部分的第1個及最後一個字元,其它的用*代替:

public static String spliteEmail(String email) {/**傳入郵箱地址*/   String newEmail = email.split("@")[0];/**擷取到郵箱@前面部分*/   String[] mails = new String[newEmail.length()];   StringBuffer sb = new StringBuffer();   if (mails.length > 0) {      if (mails.length < 3) {/**如果郵箱@前面字條小於3個,則顯示全部完整郵箱地址*/         return email;      }      else {/**郵箱地址字元處理*/         for (int i = 0; i < mails.length; i++) {            if (i >= 1 && i < mails.length - 1) {               sb.append("*");            }            else {               sb.append(newEmail.charAt(i));            }         }         return sb.toString() + "@" + email.split("@")[1];      }   }   else {      return "";   }}
2,手機號碼處理(只顯示手機號的前3及後3數字,中間用*代替):
public static String splitePhone(String phone) {   String[] tel = new String[phone.length()];   StringBuffer sb = new StringBuffer();   if (tel.length > 0) {      for (int i = 0; i < tel.length; i++) {         if (i > 2 && i < 7) {            sb.append("*");         }         else {            sb.append(phone.charAt(i));         }      }   }   return sb.toString();}
另外幾個常用的正則表達示:
/**@description:判斷是否是身份證格式*/public static boolean isIDCardNo(String cardNo) {   Pattern pattern = Pattern.compile("(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)");   Matcher matcher = pattern.matcher(cardNo);   return matcher.matches();}/**判斷輸入的是否是中文*/public static boolean isChineseChar(String inputString) {   Pattern pattern = Pattern.compile("^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$");   // Pattern pattern = Pattern.compile("^[\\u4E00-\\u9FA5]");   return pattern.matcher(inputString).matches();}/**匹配非負浮點數*/public static boolean isNotNegativeFloat(String inputString) {   Pattern pattern = Pattern.compile("^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$");   return pattern.matcher(inputString).matches();}


Android開發工具 + 生產力類(小方法)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.