Validate mobile phone numbers

Implement a validation rule for your leads' mobile field that prevents users from inadvertently entering invalid characters or digits in the phone field.

Collecting and storing valid mobile phone numbers of your leads is essential for effective communication in your CRM. You can accomplish this by preventing users from inadvertently entering invalid characters or digits in the phone fields. For example, mandate the entry of numbers, disallow letters and spaces, and restrict the total number of digits to 13, among other specifications. Wouldn't it be great if there were an automatic error detection mechanism that checks the mobile number entered and throws the relevant error? A custom function coupled with a validation rule can help you do just that.

All you need to do is create a validation rule with a function for the "Mobile" field in the leads module. Upon entering the mobile number, this rule ensures that it adheres to the validations specified in the code, reducing errors and incorrect data. If invalid, it alerts the user with the appropriate message to enter a valid mobile number. Read on to learn more.

Permissions and availability

  • Users with the Module Customization permission can create and update validation rules.
  • Users with the Manage Extensibility permission can write custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Create a validation rule for the Leads module to validate the number entered in their Mobile field. Learn more
  • Write a custom Deluge function that checks and alerts users when the mobile number doesn't adhere to the specifications. Learn more
  • Test the workflow rule in a sandbox before deploying it in your production environment. Learn more

Create a validation rule

Follow these steps to create a validation rule in your Zoho CRM account:

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Select the Leads module, then click the Validation Rules tab.
  3. Click Create New Validation Rule.
  4. In the Create Validation Rule pop-up, perform the following actions:
    1. Select the layout to which the field you wish to validate belongs.
    2. Select Mobile as the field to validate.
    3. Select the validation type as Using function.
    4. Select between Save Only or Field Verify and Save under Validate On.
    5. Click Next.
  5. In the Configure Function page, click Write your own.
  6. Enter a Name, Display Name, and a description if needed, then click Create. For example: "Validate the mobile field".
  7. In the Deluge Script Editor, do the following:
    1. Copy and paste the code provided below.
    2. Click Save.
  8. Click Save on the validation rule page.

The code

Code Copied
entityMap = crmAPIRequest.toMap().get("record");
mobile = entityMap.get("Mobile");
response = Map();
if(mobile.isNull())
{
	response.put('status','failure');
	response.put('message','The mobile field is empty');
}
else
{
	a = mobile.getAlpha().length();
	if(a == 0 && mobile.length() > 13)
	{
		response.put('status','failure');
		response.put('message','Please enter a valid mobile number with 13 digits');
	}
	else if(a > 0 )
	{
		response.put('status','failure');
		response.put('message','Please enter a valid mobile number without alphabet');
	}
	else if(mobile.Contains(" "))
	{
		response.put('status','failure');
		response.put('message','Please enter a valid mobile number without space');
	}
	else
	{
		response.put('status','success');
	}
}
return response;

Notes

  • Make sure to use the accurate API names for their corresponding fields in the code snippet (e.g., Mobile). Learn more
  • You can customize the alert message that appears when invalid entries are made in the mobile field.
  • The code above is an example of validating a lead's mobile number to ensure it is not empty, does not contain letters or spaces, and does not exceed 13 digits. You can use this code to validate phone number fields in any other module by modifying the field name parameters.

Tip

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.

Test the solution

  1. Navigate to Leads > + Create Lead.
  2. On the Create Lead page, enter all required details, including the mobile number in the Mobile field, then click Save.
    The validation rule will be triggered.
  3. Check all the non-mandated entries, such as letters and spaces, and confirm they display the appropriate error messages under the Mobile field.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleLeads
  • Trigger PointValidation Rule
  • EditionEnterprise and above
  • ComplexityLow
  • Implementation Time15 minutes

Features used in the solution

Validation RuleDeluge ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!