0

I have an input form where I want to strip out a telephone number if entered. I've found an expression that finds the variety of UK numbers, but it only works if the only thing that is entered is a number. I need the regex to find any instance of a number within the text.

Here is what I have so far

if (preg_match_all('/^\(?(?:(?:0(?:0|11)\)?[\s-]?\(?|\+)44\)?[\s-]?\(?(?:0\)?[\s-]?\(?)?|0)(?:\d{2}\)?[\s-]?\d{4}[\s-]?\d{4}|\d{3}\)?[\s-]?\d{3}[\s-]?\d{3,4}|\d{4}\)?[\s-]?(?:\d{5}|\d{3}[\s-]?\d{3})|\d{5}\)?[\s-]?\d{4,5}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$/', $post, $match_num))
{
    $error[0] = 1;
    $error[2] = 'error text';
    $error[4] = $match_num;
}
4

1 回答 1

1

Just remove the ^ and $ from the start and end. This will allow the regex to match anywhere.

于 2012-11-13T20:51:28.933 回答