How do i change any of the following to just numbers
1-(999)-999-9999
1-999-999-9999
1-999-9999999
1(999)-999-9999
1(999)999-9999
i want the final product to be 19999999999
How do i change any of the following to just numbers
1-(999)-999-9999
1-999-999-9999
1-999-9999999
1(999)-999-9999
1(999)999-9999
i want the final product to be 19999999999
The easiest way would be to strip everything out of your string that's not a number and then see if you end up with a 10 digit number (or 11 if you're making the 1 mandatory):
$string = "1-(999)-999-9999";
$number = preg_replace('/[^0-9]/', "", $string); // results in 19999999999
if (strlen($number) == 11)
{
// Probably have a phone number
}
try
preg_replace('\D', '', $string);
This will filter out any non digits.
You dont really need regex for this...
$number = str_replace(array('-', '(', ')'), '', $number);