Phone number formatting

10/06/2007

Phone number formatting has always been a difficult one. Learn how you can enforce some simple formatting rules using a matching pattern.

The difficulty arises from the fact that almost every brand or business has its own formatting rules, sometimes reasonable, sometimes outright weird.
You can use this feature to specify the rules exactly the way you want regardless of what the users enter.

Formatting pattern by example

Pattern: ###-##-##
Input: 321 09-33
Output: 321-09-33

Pattern: ###.##.##
Input: 321 09-33
Output: 321.09.33

Pattern: ### . ## . ##
Input: 321 09-33
Output: 321 . 09 . 33

Pattern: (###) ### ## ##
Input: 821-321 09-33
Output: (821) 321 09 33

Formatting logic

The system applies the following logic to the formatting process:
1. Take user input and strip off any separators (spaces, hyphens, dots, commas, etc)
2. Stop formatting if any letters are encountered. E.g. 0800-call-4-help will not be formatted, but a warning will be raised and recorded in the order details
3. Match numbers entered by the user to #(pound sign or hash) and fit any other characters from the formatting string in their respective places.
4. Stop formatting, raise an warning and record it in the order details if there are more or less numbers in the user input than #’s in the formatting string.

Multiple formats

The same field may be used to enter numbers with different formatting. E.g. landlines like (456) – 222 33 44 and free-phones like 1-800-234-567. Specify multiple allowed formats one per line. The system will try to match user input to one of the patterns and give a warning if none matches.

  • (###) – ### ## ##
  • 1-800 – ### ###
  • 1-800 – ### ####
  • 1-300 – ## ## ##

When a user enters 1-800 number it will be matched against one of 1-800 patterns. If a user enters a 1-300 number it will be matched against a 1-300 pattern even if it has the same number of digits as one of 1-800 patterns.

Where to find this feature

Formatting patterns can be entered into Field editor right on Preview page or on Fields page under Template fields tab.

Preview page example

Web-to-print number formatting/

Fields page exampleWeb-to-print number formatting

/

/

/

See also: