I've a user form where I take a phone number as input in one of my fields. I have two seperate RegEx statements checking on the input.
First one is:
preg_match('/^([\(]{1}[0-9]{3}[\)]{1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$/', $phone);
and it works great. It can identify many different formats i.e. 222-333-4444 or 2224445555.
On the other hand when I try:
preg_replace('/\+?1?[-\s.]?\(?(\d{3})\)?[-\s.]?(\d{3})[-\s.]?(\d{4})/g', '($1) $2-$3', $phone);
which is supposed to format incoming string into (222) 333-4444 format, $phone is unchanged after the preg_replace() call.
Any help will be much appreciated!