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 node = document.querySelector('.node-well')
    if (node){
      	console.log("fired!");
        //create ids for button and input elements
        angular.element(document.getElementsByClassName("next-btn")).attr('id', '123');              
        angular.element(document.getElementsByClassName("form-control")).attr('id', '222');

        //associate a function with button
        document.getElementById("123").addEventListener("click", function(event){
  	    
        //prevent submission of button  
        event.preventDefault();  
          
        //get input value ( address )  
        var val = document.getElementById("222").value;
        
        //check if address contains any digits ( streeet numbers )";
        var matches = val.match(/\d+/g);
            if (matches != null) {
            console.log("{address} submitted!");
            //alert("Submitted!");
              
            var scope = $('.app').scope()
		    scope.next()              
            return true;
            }
            else{
            console.log("{address} rejected!");
            alert("You must eneter a valid address");          
            return false;
            }    
      });
      	// Clear Interval Function when node is 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 )