PHP:如何为PT手机创建regexp to 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