Validate and Format Phone Numbers in Zoho Creator with Deluge

Format Phone Numbers as (678) 800-1234 in Zoho Creator

Users type phone numbers however they like — dots, dashes, spaces, a leading 1, parentheses. That variety makes numbers impossible to search, deduplicate, or hand to an API. This pair of scripts normalises every number to (678) 800-1234 on save, and rejects anything that is not ten digits.

Tidied up from the original. Three changes. The original called getAlphaNumeric(), which keeps letters as well as digits — so 555-CALL-NOW passed the length check and produced nonsense; this uses replaceAll("[^0-9]",""). It raised an alert but did not stop the save, so bad data still landed; cancel submit is added. And the reusable function referred to its own argument as input.phonefield, which is legacy syntax — current Creator addresses function arguments by bare name. An empty else block was dropped, and a leading country code is now tolerated rather than rejected.

Before you start

One single-line field to validate — Phone_additional in this example. Rename it in both scripts to match your form. Nothing else is required.

Part 1 — the validation script

// Trigger: On Add / On Edit > On Validate
if(!isBlank(input.Phone_additional))
{
    digits = input.Phone_additional.replaceAll("[^0-9]","");

    // Tolerate a leading US country code
    if(digits.length() == 11 && digits.startsWith("1"))
    {
        digits = digits.subString(1,11);
    }

    if(digits.length() != 10)
    {
        alert "Phone number must be 10 digits. Received " + digits.length() + ".";
        cancel submit;
    }

    input.Phone_additional = thisapp.Update.PhoneFormat(digits);
}

Part 2 — the reusable function

Create this as a standalone function so any form in the app can call it. Keep the name Update.PhoneFormat and the script above works unchanged.

string Update.PhoneFormat(string phonefield)
{
    digits = phonefield.replaceAll("[^0-9]","");
    if(digits.length() != 10)
    {
        return phonefield;      // hand back untouched rather than throw
    }
    return "(" + digits.subString(0,3) + ") " + digits.subString(3,6) + "-" + digits.subString(6,10);
}

Notes

  • Why the function re-strips the digits. It is defensive: called from elsewhere with raw input, it still behaves. A helper that only works when its caller has already cleaned the data is a helper that breaks the first time someone else uses it.
  • It returns the input untouched on a bad length rather than throwing. A formatting helper should not be able to take down a form.
  • On Validate, not On Success. On Validate can still cancel the save. By On Success the record is already written.
  • International numbers. This is US and Canada only by design. For anything global, do not pattern-match — use a validation service, such as the Neutrino script elsewhere in this section.

This script is part of the free Creator Scripts Deluge Library.

All 39 Deluge scripts, the full Zoho Creator course, and every downloadable asset are now free. Get free access →

    • Related Articles

    • Generate Random Numbers in Zoho Creator

      Deluge has no random(). That is a surprise the first time you need a reference code, a raffle winner or a sampling key. There are two honest ways around it, and which one you want depends on whether anybody would benefit from predicting the result. ...
    • Parse, Validate and Locate a Phone Number with the Neutrino API

      Bad phone numbers quietly destroy outbound campaigns. This script runs every number through the Neutrino API before it is trusted: it confirms the number is real, tells you whether it is a mobile or a landline, normalises it to E.164, and writes it ...
    • How do I fix mobile phone field not persisting when creating tickets for new customers in Zoho Desk?

      Solving the Mobile Phone Field Mystery in Zoho Desk Solving the Mobile Phone Field Mystery: A Complete Guide to Zoho Desk Introduction: When Customer Data Goes Missing Picture this: Your support team creates a ticket for a new customer, carefully ...
    • What is Zoho CRM Phone Integration?

      Zoho CRM Phone Integration enables users to integrate their phone system with Zoho CRM. This feature allows calls to be made directly from the CRM and automatically logs them, enhancing communication efficiency and tracking. This integration enhances ...
    • Send Text Messages from Zoho Creator with GoTo Connect (formerly LogMeIn Jive)

      Two functions send a text message from inside a Zoho Creator app through GoTo Connect: one keeps an OAuth access token fresh, the other sends the message. Wire the second to a button and your users can text a contact without leaving the record. ...