javaRegex筆記

來源:互聯網
上載者:User

標籤:return   mat   util   blog   row   號碼   運算式   for   code   

import java.util.regex.Matcher;  import java.util.regex.Pattern;  import java.util.regex.PatternSyntaxException;    public class PhoneFormatCheckUtils {        /**      * 大陸號碼或香港號碼均可      */      public static boolean isPhoneLegal(String str)throws PatternSyntaxException {          return isChinaPhoneLegal(str) || isHKPhoneLegal(str);      }        /**      * 大陸手機號碼11位元,匹配格式:前三位固定格式+後8位任意數      * 此方法中前三位格式有:      * 13+任意數      * 15+除4的任意數      * 18+除1和4的任意數      * 17+除9的任意數      * 147      */      public static boolean isChinaPhoneLegal(String str) throws PatternSyntaxException {          String regExp = "^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$";          Pattern p = Pattern.compile(regExp);          Matcher m = p.matcher(str);          return m.matches();      }        /**      * 香港手機號碼8位元,5|6|8|9開頭+7位任意數      */      public static boolean isHKPhoneLegal(String str)throws PatternSyntaxException {          String regExp = "^(5|6|8|9)\\d{7}$";          Pattern p = Pattern.compile(regExp);          Matcher m = p.matcher(str);          return m.matches();      }         }  

 

javaRegex筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.