我更新与 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);
.

注意^$。这些确保只有电话号码,而且没有。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top