<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 驗證國際電話號碼的 Java 正則表達式 > 原文: [https://howtodoinjava.com/regex/java-regex-validate-international-phone-numbers/](https://howtodoinjava.com/regex/java-regex-validate-international-phone-numbers/) 在本正則表達式教程中,我們將學習根據 [ITU-T E.123](https://en.wikipedia.org/wiki/E.123) 指定的行業標準符號來驗證國際電話號碼 全球范圍內用于打印國際電話號碼的規則和約定千差萬別,因此除非您采用嚴格的格式,否則很難為國際電話號碼提供有意義的驗證。 幸運的是,ITU-T E.123 指定了一種簡單的行業標準符號。 此符號要求國際電話號碼包含一個加號(稱為國際前綴符號),并且只能使用空格分隔數字組。 同樣,由于國際電話編號計劃([ITU-T E.164](https://en.wikipedia.org/wiki/E.164)),電話號碼不能包含超過 15 位的數字。 使用的最短國際電話號碼包含七個數字。 ## 1\. 驗證國際電話號碼的正則表達式 > **正則表達式:`^\+(?:[0-9] ?){6,14}[0-9]$`** ```java ^ # Assert position at the beginning of the string. \+ # Match a literal "+" character. (?: # Group but don't capture: [0-9] # Match a digit. \\s # Match a space character ? # between zero and one time. ) # End the noncapturing group. {6,14} # Repeat the group between 6 and 14 times. [0-9] # Match a digit. $ # Assert position at the end of the string. ``` 以上正則表達式可用于驗證基于 ITU-T 標準的國際電話號碼。 讓我們看一個例子。 ```java List phoneNumbers = new ArrayList(); phoneNumbers.add("+1 1234567890123"); phoneNumbers.add("+12 123456789"); phoneNumbers.add("+123 123456"); String regex = "^\\+(?:[0-9] ?){6,14}[0-9]$"; Pattern pattern = Pattern.compile(regex); for(String email : phoneNumbers) { Matcher matcher = pattern.matcher(email); System.out.println(email +" : "+ matcher.matches()); } Output: +1 1234567890123 : true +12 123456789 : true +123 123456 : true ``` ## 2\. 驗證 EPP 格式的國際電話號碼 此正則表達式遵循[可擴展配置協議](https://en.wikipedia.org/wiki/Extensible_Provisioning_Protocol)(EPP)指定的國際電話號碼符號。 EPP 是一個相對較新的協議(于 2004 年最終確定),旨在用于域名注冊機構和注冊商之間的通信。 越來越多的域名注冊機構使用它,包括`.com`,`.info`,`.net`,`.org`和`.us`。 這樣做的意義在于,越來越多的人使用和認可 EPP 樣式的國際電話號碼,因此提供了一種很好的替代格式來存儲(和驗證)國際電話號碼。 EPP 樣式的電話號碼使用`+CCC.NNNNNNNNNNxEEEE`格式,其中`C`是 1-3 位國家/地區代碼,`N`最多 14 位數字,`E`是(可選)擴展名。 國家/地區代碼后必須加上加號和加點。 僅在提供擴展名時才需要字面“`x`”字符。 > **正則表達式:`^\+[0-9]{1,3}\.[0-9]{4,14}(?:x.+)?$`** ```java List phoneNumbers = new ArrayList(); phoneNumbers.add("+123.123456x4444"); phoneNumbers.add("+12.1234x11"); phoneNumbers.add("+1.123456789012x123456789"); String regex = "^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$"; Pattern pattern = Pattern.compile(regex); for(String email : phoneNumbers) { Matcher matcher = pattern.matcher(email); System.out.println(email +" : "+ matcher.matches()); } Output: +123.123456x4444 : true +12.1234x11 : true +1.123456789012x123456789 : true ``` 您可以隨時在正則表達式上方進行編輯并使用它來匹配更嚴格的電話號碼格式。 學習愉快!
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看