PHP:PT携帯電話のPREG_MATCH()に正規表現を作成する方法
-
16-09-2020 - |
質問
php ...
のregexpに関連しています。ポルトガルの携帯電話をフィルタリングするには、 regexp を作成する必要があります。(私はそれを理解しています)
規則:
The integer/string must have 9chars;
The first char must be a '9';
The second one can be '1,2,3,6' (Chars are separeted by commas);
The other chars must be in range of '0-9';
. 解決
#9[1236][0-9]{7}#
.
それはそれをするべきです;)
説明:
# <-- delimiter
9 <-- 9
[1236] <-- either of the chars in the brackets
[0-9]{7} <-- 0-9 7 times
# <-- delimiter
.
使用:有効な電話番号が有効な電話番号かどうかを確認したい場合は、
$isValid = preg_match('#^9[1236][0-9]{7}$#', $phoneNumber);
.
^
と$
に注意してください。これらは電話番号だけがもうありません。
所属していません StackOverflow