Jump to content

Modifying phone field php


dannyboy1977

Recommended Posts

Hi All,

I'm trying to modify my phone field php script for when a member on my site enters a phone number in a form. My script is as follows:


function format_phone_data($phone_number=0)
{
if ($phone_number)
{
$PhoneNumber = ereg_replace( "[^0-9]", "", $phone_number ); // Strip out non-numerics
if( ereg( "^([0-9]{3})([0-9]{3})([0-9]{4})$", $PhoneNumber, $NumberParts ) )
                return "(" . $NumberParts[1] . ") " . $NumberParts[2] . "-" . $NumberParts[3];
        else
              return $phone_number;
}
else
return $phone_number;
} //end of function format_phone_data


This script displays the phone field as (123) 456-6789 on my website
This script is fine but I want to use two different phone sets. first like above (123) 456-7890 and secondly (12) 3456-7890. So when a member of my website enters 123-456-7890 in the phone field it will display as (123) 456-7890 and if they enter 12-3456-7890 it will display as (12) 3456-7890.

Can anyone help me????

Dan.
Link to comment
https://forums.phpfreaks.com/topic/24646-modifying-phone-field-php/
Share on other sites

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.