PLEASE NOTE: This script is provided to help you get started. Unfortunately, our free support does not include custom scripts. Any competent JS developer should be able to manipulate this script for your needs. Please contact us if you need help to find a developer. Please thoroughly test before use.

  • When using real time address verification sometimes Google allows addresses through without a house number, street address, or post code.
  • To address this we provide a script to ensure a user cannot proceed to the next node unless the address is valid.

In a question node of type “address”, setup a node level script to look like this:

Then copy paste the following code:

<script>
  var interval = setInterval(nodeLoaded, 500);
  
  // Check if node is loaded
  function nodeLoaded() {
    var button = document.querySelector('#forward-button');
    var input = document.querySelector('.form-control');
    
    // If the button and input are not null, they are in the DOM
    if (button && input) {
      console.log("Button and input are loaded!");

      //attach the event listener
      button.addEventListener("click", function(event){
      
        //get input value ( address )  
        var val = input.value;
        
        //check if address contains any digits (street numbers)";
        var matches = val.match(/\d+/g);
        if (matches != null) {
            console.log(val + " submitted!");

            // If Angular is available in your environment
            if(window.angular){
                // Get the Angular scope
                var scope = angular.element(document.querySelector('.app')).scope();

                // If the scope and next function are available
                if(scope && typeof scope.next === "function"){
                    // Use Angular's digest cycle to update the view
                    scope.$apply(function(){
                        scope.next();
                    });
                }
            }
            
        } else {
            console.log(val + " rejected!");
            alert("You must enter a Valid Complete address");          
            //prevent submission of button
            event.preventDefault(); 
            return false;
        }    
      });

      // Clear Interval Function when button and input are loaded
      clearInterval(interval);
    }
  }
</script>

You can see a demo of this here:

https://test2.leadshook.io/survey/I7X1ZW34Bh5WXisLixiu9pRvi2sxmSwtIQatHAxu

( Try entering a city name, eg: “Sydney”. It wont let you submit the address as it contains no street number )