输入框输入经纬度,并用逗号隔开,js做校验

js校验经纬度,经纬度在同一个输入框输入,需要做校验,js很菜,自己鼓捣半天才搞出来,特地记下,方便以后使用

function isLngAndLat() {
        var index = document.getElementById("lngAndLat").value;
        // console.log(typeof index);
        // console.log(index);  -- string
        var array = index.split(",");
        console.log(typeof array); -- object
        // console.log(array[0]); 
        // console.log(typeof array[0]); -- string 没有值就是undefined
        // console.log(array[1]); 
        // console.log(typeof array[1]); -- string 没有值就是undefined
        if (array[0] == undefined || array[1] == undefined){
            alert("请输入经度和纬度,经纬度用','隔开!");
            return false;
        }
        var longreg = /^(\-|\+)?(((\d|[1-9]\d|1[0-7]\d|0{1,3})\.\d{0,6})|(\d|[1-9]\d|1[0-7]\d|0{1,3})|180\.0{0,6}|180)$/;
        if(!longreg.test(array[0])){
            alert('经度整数部分为0-180,小数部分为0到6位!');
            return false;
        }
        //纬度,整数部分为0-90小数部分为0到6位
        var latreg = /^(\-|\+)?([0-8]?\d{1}\.\d{0,6}|90\.0{0,6}|[0-8]?\d{1}|90)$/;
        if(!latreg.test(array[1])) {
            alert('纬度整数部分为0-90,小数部分为0到6位!');
        }
    }
在于GIS相关的软件中经常要输入经纬度数值,而基于MFC Edit控件的经纬度输入控件需 要创建三个Edit编辑框,来分别输入度、分、秒数值,并且需要分别进行输入范围和有效 性的检验。该基于BCGControlBar的经纬度输入控件实现了在一个输入窗口中分别按照度 、分、秒三个值域来输入经纬度数值,并同时进行了输入分有效性和输入范围的检验。经 纬度中的度、分、秒字段均通过数字键盘直接输入数值,也可通过微调按钮或者键盘的上 下键进行数字的增减,你可以通过左右键进行度、分、秒输入域的切换。该控件可以设置 度的输入范围,默认的度范围是0~89。该1.1版本修复了键盘直接输入数值的逻辑问题。 In the GIS-related software often have to enter the latitude and longitude values, and MFC Edit control based on the latitude and longitude input controls need to create three Edit edit box to enter the degrees, minutes and seconds values, and the need for input range and validity of the test. The BCGControlBar-based latitude and longitude input control realizes the input of the latitude and longitude values in degrees,minutes,and seconds in one input window, and simultaneously verifies the validity of the input points and the input range.The degrees, minutes, and seconds fields can be entered directly through the numeric keypad, also can be fine-tuning button or the keyboard up and down keys to increase or decrease the number, you can use left and right keys for degrees, minutes and seconds to switch the input field. The control can set the input range of degree, the default range is 0 ~ 89.The 1.1 version fixes the logic of keyboard input values directly.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值