Skip to content Skip to sidebar Skip to footer

How To Validate Latitude And Longitude Separately In Javascript?

if ((get.latitude).match(/((\d+)+(\.\d+))$/)) Analytics_Latitude = get.latitude; else Analytics_Latitude = 'undefined'; if ((get.longitude).match(/((\d+)+(\.\d+))$/))

Solution 1:

Before trying to regex the value, you got to check if it exists.

You can do this this way:

if(typeofget.latitude !== 'undefined'){...}

Second thing is that putting () between string and match seems to be wrong...

Change this:

(get.latitude).match(/((\d+)+(\.\d+))$/)

to this:

get.latitude.match(/((\d+)+(\.\d+))$/)

Third thing is that latitude is probably some float point number... so before acting as on string, you need to convert it:

get.latitude.toString().match(...)

Post a Comment for "How To Validate Latitude And Longitude Separately In Javascript?"