Format Phone Numbers

We have had a few requests to modify phone numbers to fit a specific format, so we have made that a feature!  Smarty (our backend document builder) offers some great features for formatting dates, numbers, but not phone numbers. 

Fortunately, it is really easy to add features like this – so we created some custom functionality.

To use the new phone formatting function, simply put "|phone_format" after your variable name.  The default format is (XXX) XXX-XXXX, but you can indicate any format you want.  Here are some examples:

$phone =  "123 456 7890"

{$phone|phone_format:"%3-%3-%4"} = 123-456-7890

{$phone|phone_format:"(%3) %3-%4"} = (123) 456-7890

{$phone|phone_format:"%3.%3.%4"} = 123.456.7890

As you can see, the %X (where X is a number) indicates the number of digits to show in each block of numbers.  This is very customizable.

If you have any other ideas/needs for custom formatting or other customized functions, please contact us and we’ll see what we can do!

Have more questions? Submit a request

3 Comments

  • Avatar
    Mariette van Wyk

    Hi, how can I remove the leading zero from my phone number?
    If I get the number 083xxxxxxx, I need to display (+27) 83 xxx xxxx

  • Avatar
    Jeremy Clarke

    Hi Mariette,

    You can do something like this:

    {if $PhoneNumber[0] == "0"}{$PhoneNumber = substr($PhoneNumber, 1)}{/if}

    This will look at the first character in the phone number and if it is 0 then create a substring ignoring the first 0.

  • Avatar
    Mariette van Wyk

    Working perfectly, thanks Jeremy!

Please sign in to leave a comment.
Powered by Zendesk