- 04 May 2022
- 2 Minutes to read
- DarkLight
Making Sure a Phone Number is Valid
- Updated on 04 May 2022
- 2 Minutes to read
- DarkLight
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.
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.
Log in to dashboard.nexudus.com if you aren't already.
Click Settings > Validation rules.
Click Add rule.
Click on Manual entry.
Name your rule.
Add a Description of the rule.
Enable the This rule is active toggle.
Select Customer in the Record type drop-down list.
Add the Error message to display if the validation rule is not met
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.
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
Log in to dashboard.nexudus.com if you aren't already.
Click Settings > Validation rules.
Click Add rule.
Click on Manual entry.
Name your rule.
Add a Description of the rule.
Enable the This rule is active toggle.
Select Customer in the Record type drop-down list.
Add the Error message to display if the validation rule is not met
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}$")
- 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
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.