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}
- Check this guide on how to create a custom field
- Make sure to use text type as the custom field type.
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}
<script>
const mobile = '{YOUR_MOBILE_FIELD|national|no_brackets|no_spaces|no_hyphens|no_leading_plus}';
console.log(mobile);
//Check the length
const 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 );
</script>
- Click “Add Scripts”
- Name your script
- Set the type to “Script”
- Set the event to fire on “Exit”
- 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.