Friday 2 June 2017

Google Maps API - Address validation

I'm using Google maps API and Geocoder to let users add a map to their posts in a Node app. Everything is working very well with one exception. If a user tries to input either an empty address or an invalid address like a symbol it crashes the website. For example if a user tries to use "!@#$$" as an address it crashed the website.

How can I prevent this? My first thought is Address validation.

I tried the following but I was told handing this on the browser side is risky:

$( "#myForm" ).submit(function( event ) {

if(/^[a-zA-Z0-9- ]*$/.test($("#location").val()) == false) {
alert("Location can have only alphabets and numbers.");
event.preventDefault();
}

if ($("#location").val() == 0 ){
    event.preventDefault();
     alert('An address must be included.')

}
});



via AndrewLeonardi

No comments:

Post a Comment