Validating Phone Numbers Based on Country

Starting with Directory Update v1.9 and Directory Manager v1.6, we have the ability to validate telephone number format (using Regular Expressions) based on the country selected. There are several parts to this feature that must be configured.

The first part is that a phone number validation format for the countries that you use must be configured in the validations section of the DirectorySettings.XML file. Below is an example of some validation formats including one for the United States (US), Great Britain (GB) and Australia (US) from the validations sectoin of the DirectorySettings.XML file.

  <validation format="US" formatExample="Example: (808) 123-4567 or 808-123-4567 x4321" 
    regularExpression="((\(\d{3}\) ?)|(\d{3}-))\d{3}-\d{4}(( x)\d{1,5}| )?" />
  <validation format="GB" formatExample="Example: +44 (0) 123 456 7890 " 
    regularExpression="(\+44 )(\(\d\) )((\d{3} )(\d{3} )\d{4}|(\d{4} )\d{6})(( x)\d{1,5}| )?" />
  <validation format="AU" formatExample="Example: +61 2 1234 5678" 
    regularExpression="(\+61 )((\(\d\))?\d )(\d{4} )\d{4}(( x)\d{1,5}| )?" />

Note that in the example above, the validation format name must match the short country name (such as US, GB, AU, etc..). You can see a list of the country codes in the DirectorySettings>XML file. Additional RegEx formats can be found at RegEx Library. Ithicos Solutions support cannot provide regular expression support for you.

Next, after you have defined the validation formats, locate country section of the DirectorySettings.XML file. The setPhoneValidation option must be set to "true".

<field id="country" label="Country" type="dropdown" visible="true" editable="true" setPhoneValidation="true" required="true">

Finally, for each phone number attribute that you want to use the country validation code, you must add the validation format name "country" to the phone number attributes. Below is an example of editing the

<field id="officePhone" label="Office Phone" type="text" visible="true" editable="true" validationFormat="country" required="true"/>