I have a text input for latitude typing and another for longitude.
I would like the field to allow typing only the characters valid for latitude and longitude.
I believe the field should only accept numbers, "." and "-", correct?
At first I think that something with regex works, but I do not know what regex would look like:
// Campo para latitude e longitude;
$(".latitude, .longitude").on('keypress', function (event) {
var regex = new RegExp(??????);
var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
if (!regex.test(key)) {
event.preventDefault();
return false;
}
});