1

I have walk through much to find valid regex in javascript to validate latitude and longitude separatly.

but in vain..

tried the following but not working..

    var latlngVal = /^-?([0-8]?[0-9]|90)\.[0-9]{1,6},-?((1?[0-7]?|[0-9]?)[0-9]|180)\.[0-9]{1,6}$/;
    if (!latlngVal.test(this.value)) {
       //logic
    }

can anybody tell me the easiest way to validate the latitude and longitude entered in the textbox.

Or is there any mvc annotation to validate latitude and longitude?

4

1 回答 1

0

我通过以下方式做到了..

$(".longitude").focusout(function () {
    debugger;
    var lngVal = /^-?((1?[0-7]?|[0-9]?)[0-9]|180)\.[0-9]{1,6}$/;
    if (!lngVal.test(this.value)) {
       //logic
    }
});

用于纬度验证使用

var latVal = /^-?([0-8]?[0-9]|90)\.[0-9]{1,6}$/;

于 2013-11-13T05:26:30.397 回答