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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.