Help using preg_match for phone numbers

Posted by Kirk on Stack Overflow See other posts from Stack Overflow or by Kirk
Published on 2010-05-13T17:59:36Z Indexed on 2010/05/13 18:04 UTC
Read the original article Hit count: 174

Filed under:

how would i write an if statement that would find phone numbers and store them to a variable. Here is what i have so far but its not working.

if (preg_match('/^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$
/', $buffer, $matches))
{
    $phonenumber = html_entity_decode($matches[1]);         
}

© Stack Overflow or respective owner

Related posts about preg-match