This guide will teach you on how to setup your Decision Tree to either only accept 6 or 10 digit African numbers.

The only way to filter the numbers is for Leadshook to do the initial mobile validation for 6 or 10 digits then use a script to count the total digits then create a path to either accept or reject the number.

Step 1: Create the custom field {mobile_length}

Step 2: Add the script below to the node capturing the mobile field and fire on EXIT

  • The script below will grab the number input and strip off plus signs, hyphens, brackets and spaces.
  • It will then count the number of digits and store that value to {mobile_length}
   var mobile = '{YOUR_MOBILE_FIELD|national|no_brackets|no_spaces|no_hyphens|no_leading_plus}';


//Check the length
    var length = mobile.length;
    //If it's 6 digits
    if(length === 6) {
        console.log("The phone number has 6 digits");
      DT.setField('mobile_length', length);
    //If it's 10 digits
    else if(length === 10) {
        console.log("The phone number has 10 digits");
      DT.setField('mobile_length', length);
    //If it's neither 6 nor 10 digits
    else {
        console.log("Invalid input. The phone number should have either 6 or 10 digits.");
         DT.setField('mobile_length', "Invalid input. The phone number should have either 6 or 10 digits for Africa. Please ensure you turn on Data Validation on your Decision Tree");

    console.log("Mobile Length: " +length ); 
  1. Click “Add Scripts”
  2. Name your script
  3. Set the type to “Script”
  4. Set the event to fire on “Exit”
  5. Paste the code and update the value for “YOUR_MOBILE_HERE” then save it.

Important: Please ensure to replace “YOUR_MOBILE_FIELD” to the exact same field you are using to capture mobile.

Step 3: Add a Decision Node and create paths for 6 and 10. You can then Loop it depending on how you want to set it up.

  • The Decision Node will evaluate and create the pathing for 6 or 10 digit mobile numbers so you can easily reject or accept them.

Leave a Reply

Your email address will not be published. Required fields are marked *