Validate phone numbers of leads

Validate lead phone numbers and automatically mark a checkbox field when they are valid to ensure seamless communication and data integrity.

When you create leads from various sources in your CRM, you must ensure their phone numbers are valid. Validation involves checking the phone number format, such as country and area codes, minimum number of digits, presence of special characters, and spaces, if any. This validation helps ensure you can contact your leads and increases your chances of converting them into customers. Additionally, validating phone numbers helps reduce the number of invalid or fake leads in your database, saving you time and money in the long run. Although you can use a validation rule to specify certain conditions, it's not exhaustive in itself.

Using functions, you can set specific conditions to validate a lead's phone number. If the phone number meets those conditions, you can auto-update a checkbox field to show that the number has been validated. You can use this checkbox field in other automations as a determinant of lead qualification.

Permissions and availability

  • Users with the Modules Customization permission can add custom fields.
  • Users with the Manage Automation permission can create and update workflow rules.
  • Users with the Manage Extensibility permission can create custom functions.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Add a Checkbox field in the Leads module. This is where the function will update whether the phone number is valid or invalid. Learn more
  • Create a workflow rule for the Leads module that triggers every time a lead is created or edited. Learn more
  • Write a custom Deluge function and link it up with the workflow rule. Learn more
  • Test the workflow rule in a sandbox before deploying it to your production environment. Learn more

Add a custom field

The first step is adding a custom checkbox field to the Leads module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Leads module to open the layout editor.
  3. Drag and drop the Checkbox field from the New Fields tray to the desired section of the layout.
  4. Name the checkbox field (e.g. "Valid Phone") and define its properties as required.
  5. Once you have finished, click Save and Close.
Add Custom Field

Create a workflow rule

Next, create a workflow rule that marks the checkbox when the phone number is valid.

  1. Navigate to Setup > Workflow Rules > +Create Rule.
  2. Select Leads from the module dropdown list.
  3. Provide a name for the rule. For example: "Validate Lead Phone Number".
  4. Add a description (optional) and then click Next.
  5. In the Execute this workflow rule based on section, do the following:
    1. Choose Record Action, then select Create or Edit from the dropdown.
    2. Check the Repeat this workflow whenever a lead is edited option.
    3. Click Next.
  6. In the Which leads would you like to apply the rule to? section, specify the condition as "<Phone> <is not empty>", then click Next.
  7. Under Instant Actions, select Function and Write your own.
  8. Provide a name and description, if necessary, for the function.
  9. On the Deluge Script Editor, do the following:
    1. Copy and paste the code given below.
    2. Click Edit Arguments.
    3. Choose Leads - Phone, then name it phone.
    4. Click the + icon to add more arguments.
    5. Choose Leads - Lead Id, and name it leadId.
    6. Click Save & Execute Script.
  10. Click Save on the workflow rule page.

The code

Code Copied
phonestr = input.phone.toString();
phnlen = phonestr.length();
if(phnlen >= 10)
{
	if(phonestr.notContains(" "))
	{
		valid = "Yes";
	}
	if(phonestr.contains(")") || phonestr.contains("(") || phonestr.contains("-"))
	{
		valid = "No";
	}
	info valid;
	if(valid == "Yes")
	{
		mp = Map();
		mp.put("Valid_Phone",true);
		update = zoho.crm.updateRecord("Leads",leadId.toLong(),mp);
		info mp;
		info update;
	}
}

Notes

  • Make sure to use the accurate API names for their corresponding fields (e.g., "Valid Phone") in the code snippet. Learn more
  • The script above is an example of validating a lead's phone number by checking if it has ten digits without any spaces or special characters and then updating a checkbox to indicate that it's valid. You can customize this code to validate phone numbers in other modules by changing the module, field names, and other parameters.

Tips

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
  • Create a custom list view or save a filter to display only the lead records selected for the "Valid Phone" field.

Test the solution

  1. Navigate to Leads > +Create Lead.
  2. On the Lead Details page, enter the lead information and phone number in the mandated format, then click Save.
    The workflow rule will be triggered.
  3. Check whether the Valid Phone field was checked to validate the number.
  4. Create a new lead record, input the phone number with parentheses (e.g., (987)6543210), then click Save.
    The workflow rule will be triggered.
  5. Check whether the "Valid Phone" field remains unchecked.

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 PointWorkflow Rule
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

Custom FieldWorkflow 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!