Why doesn't my phone number validation regular expression work? [duplicate]
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?
精彩评论