Jump to content


Photo

Modifying phone field php


  • Please log in to reply
No replies to this topic

#1 dannyboy1977

dannyboy1977
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 21 October 2006 - 10:33 AM

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.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users