Jump to content

Check for phone numbers in textarea using PHP


greens85

Recommended Posts

Hi All,

 

I guess there must be someway to do this with regex, but I'm not too hot on regex.

 

What I want to do is check a text area for the presence of a phone number, and if it is there remove it. Ideally I don't want to remove all number as there might be a need for them to use a number, for example... I am 25 years old would be fine, but entering their number wouldn't be.

 

Is there anyway of tacking this with regex, or is it going to be tricky?

 

Many thanks,

 

Greens85

Quite tricky, since phone numbers can be formatted in so many different ways. This is my attempt:

preg_replace("/\+?[0-9() -]{7,18}/", "", $text);

That'll replace anything resembling a phone number, "5555555", "+62 (555) 555-5555", etc. As long as it's at least 7 numbers long.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.