954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Simple Regex Help

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...

Ender330
Newbie Poster
18 posts since Jan 2010
Reputation Points: 10
Solved Threads: 0
 

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.

minitauros
Junior Poster
109 posts since Apr 2011
Reputation Points: 36
Solved Threads: 17
 
+558499608822 -- I want any number that starts with the country code 55 to be excluded.
preg_match('/\+(?!55)\d+/', $string);
pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: