Making Sure a Phone Number is Valid
  • 04 May 2022
  • 2 Minutes to read

Making Sure a Phone Number is Valid


You can implement validation rules to prevent users from adding or editing phone numbers that don't match a specific format.

Making Sure Phone Numbers Include Country Codes & Valid Format

Use this validation rule if you want to make sure customers phone number's country include a country code and have 14 digits or less.

This validation rule won't prevent users from adding a mismatched country code & digits combination.

If you want to control the country code and exact number of digits of the phone number, scroll down to the next tutorial on Making Sure Phone Numbers Have a Specific Country Code & Number of Digits.

  1. If the navigation menu isn't visible, click the menu icon in the top left corner of the page.

  2. Click Add rule

  3. Click on Manual entry

  4. Name your rule.

  5. Add a Description of the rule.

  6. Enable the This rule is active toggle.

  7. Select Customer in the Record type drop-down list.

  8. Add the Error message to display if the validation rule is not met

  9. Add the following snippet in the Formula field.

IsMatch(record.MobilePhone, "\\+[1-9]\\d{1,14}")

Your validation rule should look similar to the example below.

VR_PhoneNumberValidation.png

  1. Click the Save Changes button.

All set! Your validation rule is now active. You can test it by trying to add or edit a customer's phone number without a country code. If the rule is set up correctly, you should receive the error message defined in step 8.

Making Sure Phone Numbers Have a Specific Country Code & Number of Digits

  1. If the navigation menu isn't visible, click the menu icon in the top left corner of the page.

  2. Click Add rule

  3. Click on Manual entry

  4. Name your rule.

  5. Add a Description of the rule.

  6. Enable the This rule is active toggle.

  7. Select Customer in the Record type drop-down list.

  8. Add the Error message to display if the validation rule is not met

  9. Add the following snippet in theFormula field.

IsMatch(record.MobilePhone, "^\\+44\\d{10}$")

We've used 44 and 10 that are the standard values for UK number, but you should add your own value, based on your country code and number of digits you want to allow.

For example, if you wanted to make sure numbers are US-based, the formula would be:

IsMatch(record.MobilePhone, "^\\+1\\d{11}$")
  1. Add the error message you want to show users when they try to add or edit a phone number without including the defined country code or include an invalid number of digits.

Your validation rule should look similar to the one below

VR_ValidUKNumber.png

  1. Click the Save Changes button.

All set! Your validation rule is now active. You can test it by trying to add or edit a customer's phone number with a different country code. If the rule is set up correctly, you should receive the error message defined in step 8.