A Template Filter for Phone Numbers

It’s common to need to output a single phone number formatted in a different way than it’s entered by the editor. Plus if the editor has to enter multiple phone numbers in multiple fields, you cannot assume they would enter them in a consistent formatting. So here’s a Perch template filter to make your life a little easier.

The template filter uses Google’s library libphonenumber for formatting and validating phone numbers.

Example usage

You specify the country of the phone number with the country attribute. You can optionally define a default country and omit the country attribute.

The output attribute specfies how you want to format the phone number. You can check the available options in the documentation.

<a href="<perch:content id="phone_number" filter="phone" country="gb" output="tel_link">" >
    <perch:content id="phone_number" filter="phone" country="gb" output="international">
</a>

For more details head to the filter’s documentation. If you have any issues, feel free to let me know on GitHub.

link