开发者

Why doesn't my phone number validation regular expression work? [duplicate]

开发者 https://www.devze.com 2023-03-05 21:39 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: Phone number validation in PHP
This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Phone number validation in PHP

Yes iam an Regular Expression newb (-:

T开发者_运维知识库his one validates an Phone Number in the format: +00 000 00000 but it should altough validate +000000000 without an space.

I have dont try & error, but without success (-:

 $pattern = '((^\+[1-9][0-9]{0,2}(\s+[1-9][0-9]*)?\s+([0-9]+)$)|(^([0][0-9]*)?\s+([0-9]+)$))';


You can change each \s+ to \s* and it should do what you want.

The + there tells the regex to match \s one or more times. The * tells the regex to match \s zero or more times.


Why not just remove the whitespace first and then use something simple?

0

精彩评论

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