0
I have a text input for typing latitude and another for longitude.
I would like the field to allow typing only of characters valid for latitude and longitude.
I believe the field should accept only numbers, "." and "-", correct?
At first I think something with regex works, but I don’t know how the regex:
// 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;
}
});
Pass a list of examples... a mcve of an Ideone or something like... Examples of error, hits, etc. Or Regex101
– danieltakeshi