title: Why use regular expressions to validate latitude and longitude in Javascript?
body: <p>When I <a href="https://stackoverflow.com/search?q=validate+latitude+longitude+%5Bjavascript%5D">search</a> for <code>validate latitude longitude [javascript]</code>, I get answers that <a href="https://stackoverflow.com/a/28211854/27358">match digits indiscriminately</a> or <a href="https://stackoverflow.com/a/3518546/27358">match the wrong range</a> or <a href="https://stackoverflow.com/a/18690202/27358">are just too complicated to debug</a>.</p>
  
  <p>In fairness, some of these OPs did <em>ask</em> for regexes, and Javascript isn't my first language, but it seems like it would be more straightforward and less error-prone just to do the math:</p>
  
  <pre><code>function isLatitude(maybeLat) {
    var latF = parseFloat(maybeLat)
    if (isNaN(latF)) return false
    return (latF &gt;= -90 &amp;&amp; latF &lt;= 90)
  }
  
  function isLongitude(maybeLon) {
    var lonF = parseFloat(maybeLon)
    if (isNaN(lonF)) return false
    return lonF &gt;= -180 &amp;&amp; lonF &lt;= 180
  }
  </code></pre>
  
  <p>Yes, it's less terse, but it's a lot more readable than</p>
  
  <pre><code>^[-+]?([1-8]?\d(\.\d+)?|90(\.0+)?),\s*[-+]?(180(\.0+)?|((1[0-7]\d)|([1-9]?\d))(\.\d+)?)$
  </code></pre>
  
  <p>Is there some advantage to using regular expressions? Performance? Browser compatibility? Library tools that only allow regex validation? SO users showing off their mad regex sk1llz?</p>