How can I restrict an input field for enter latitude using javascript?
The following is the piece nof code which i have tried.
$('#latitude').on( "keypress",function (e) {
var keypress = e.keyCode || e.which || e.charCode;
var key = String.fromCharCode(keypress);
var regEx = /^[-|+]?[0-9]{0,2}(.[0-9]{0,6})?$/;
var txt = $(this).val() + key;
if (!regEx.test(txt)) {
if(keypress != 8){
e.preventDefault();
}else{
}
}else{
}
});
Here i found the issue that i can enter a special character at the first position. Please help me...