Jump to content
zpupster

formatting the customer_telephone

Recommended Posts

hello,

 

has anyone seen an addon that formats the telephone numbers from the customers database so that when they are called are displayed as (555)555-5555 ?

 

i have been googling and searching for a while now and have not found an answer

Share this post


Link to post
Share on other sites

I doubt that there is an addon for that. It would be something coded per site since there are so many ways to do it. I may be wrong though.

Share this post


Link to post
Share on other sites

this the function i used in invoice.php

 

<?php
function format_telephone($phone_number)
{
    $cleaned = preg_replace('/[^[:digit:]]/', '', $phone_number);
    preg_match('/(\d{3})(\d{3})(\d{4})/', $cleaned, $matches);
    return "({$matches[1]}) {$matches[2]}-{$matches[3]}";
}
?>

called it here:

<td class="main"><?php echo format_telephone($order->customer['telephone']); ?></td>

this works,

 

but should i put the function in a different area of oscommerce.  

Share this post


Link to post
Share on other sites

Hi -

 you should pop that function into includes/functions/general.php and admin/includes/functions/general.php which would allow you to use it anywhere in the site (you'd also need to remove it from invoice.php)

 

An anternative would be to use a jQuery mask on the create_account/account_edit pages so that the number input would hit the database in your desired format or run your function on the database input from create_account (but that kind of assumes that you only ever,ever,ever get US customers and would screw up existing ones - OK so that's a maybe for a new store :-((  )

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×