Normalize Phone Number
C
Cart Product Team
It would be hella cool if phone numbers all looked like
(123) 456-7891
and not
1234567891
Log In
J
Joshua Artman
I wrote a script for our AmeriCommerce store over 5 years ago that I have shared with multiple store owners to do this.
Phone Number Formats:
9 digit or fewer numbers: Not formatted
10 digit numbers: (123) 465 - 7890
11 digit numbers that start with a 1: 1 (123) 465 - 7890 [US/Canada]
If it starts with a +, does not modify number: +66 1234657890 [International]
Examples when extension is entered after the phone number:
(123) 465 - 7890 x 1234
1 (123) 465 - 7890 x 1234
Just add:
<script src='https://cdn.jsdelivr.net/gh/JoshuaA-WCCC/AmeriCommerce@1.1.3/js/FormatPhoneNumbers.min.js' defer async></script>
in the footer of your theme, right above:
</ac:pagelayout>
Full script on GitHub: https://github.com/JoshuaA-WCCC/AmeriCommerce/blob/1.1.3/js/FormatPhoneNumbers.js
J
Joshua Artman
It would also be nice if Cart is going to build out something like this, if it could include phone number validation, with something like https://www.abstractapi.com/api/phone-validation-api
J
John Beech
Useful when customers are USA or Canadians, less so when it's international but I could get behind the dashes.