I’ve got an app that users input coordinates into.
In the DB and most mapping software they use the decimal notation for lat/lng (eg. 123.1234) rather than the older format: 34N 40' 50.12"
I need to test that a value input into a form is a float, and not a string. But using parseFloat on 34N 40' 50.12" returns 34– which validates using most tests.
Here’s what I’m trying, which is a mashup of a few really clever solutions found here– but so far I can’t get the thing to work properly for all cases. The basic cases I’m testing for are:
123.1234— valid'123.1234'— valid34N 40' 50.12"— invalid'34N 40' 50.12"'— invalid123–valid'123'— valid
Here’s a jsfiddle of what I’ve been trying: http://jsfiddle.net/zfwAj/
Seems I should have posted as an answer
isNaN()should work to filter out those ones jsfiddle.net/QYMRe