Validating and Formatting Phone Numbers

Tips and Tricks - Applies to Infiniti v8.0 or later

Please note that from Infiniti v9 onwards the User Prompt question type has been renamed Text Field.

 

Phone numbers are generally formatted according to a standard, for example:

Landline: (02) 6280 6244

Mobile: 0404 111 333

 

Simple validation

A simple way to achieve phone number formatting is to validate the question in Produce so that the user is forced to enter 10 digits with no spaces.
 
If phone numbers in your area start with a 0, a number field will not work as the browser will remove leading 0's (Real numbers don't start with 0)
 

Set your text field data type to 'Number' and a character limit. On the validations tab, set a minimum length.  Finally, once it can be ensured that the number will be entered as a 10 digit string, a format string can be applied so it appears correctly in the document.

Advanced validation

Where a phone number might start with a 0 or require characters such as ( ) + you will need to set your Text Field data type to text. Validating a phone number with these requirements can be difficult and specific to a local area.

You can make use of a regular expression by selecting the validation tab in Design and selecting the type 'Regular Expression'. 

Warning: Regular expressions are a powerful yet complex form of validation. It is recommended that any use of regular expressions for validation is tested thoroughly 

Validates an Australian Mobile number - 0411 234 567

^\({0,1}((0|\+61)(4)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$ 

Validates an Australian Phone Number - including area code - (02) 6280 6244

^\({0,1}((0|\+61)(2|4|3|7|8)){0,1}\){0,1}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{2}(\ |-){0,1}[0-9]{1}(\ |-){0,1}[0-9]{3}$

Related Articles

Number through string

Text field type