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

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

I am getting latitude and longitude value from http://www.telize.com/geoip in my js file now I want to validate that value using javascript... Here I am getting this error like Uncaught TypeError: undefined is not a function

1 Answers1

0

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

You can do this this way:

if(typeof get.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(...)
Flash Thunder
  • 11,672
  • 8
  • 47
  • 91