开发者

PHP: how to create an regexp to preg_match() for PT Mobile phones?

i'm newer related to Regexp on PHP...

I need to create an Regexp to filter Portugue开发者_如何学Cse Mobile Phones, can anybody help me and explain how i do it? (To i understand it)

Rules:

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}#

That should do it ;)

Explanation:

# <-- delimiter
    9 <-- 9
    [1236] <-- either of the chars in the brackets
    [0-9]{7} <-- 0-9  7 times
# <-- delimiter

Use: If you want to check whether something is a valid phone number, use:

$isValid = preg_match('#^9[1236][0-9]{7}$#', $phoneNumber);

Notice the ^ and $. These ensure there is only the phone number and nothing more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜