Hello,

I need to find a way to use regex to exclude a phone number like this:

+558499608822

I want any number that starts with the country code 55 to be excluded.

For some reason \+55 does not work.

Thanks for the help...

Recommended Answers

You could try: preg_match('/^\+?55[0-9]+$/', $string);

\+? means: a + 0 or 1 times,

55: both need to be present

[0-9]+, any number, 1 or more times.

Jump to Post

All 2 Replies

You could try: preg_match('/^\+?55[0-9]+$/', $string);

\+? means: a + 0 or 1 times,

55: both need to be present

[0-9]+, any number, 1 or more times.

+558499608822 -- I want any number that starts with the country code 55 to be excluded.

preg_match('/\+(?!55)\d+/', $string);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.