I have two input fields, latitude and longitude. In it I should only allow the entry of numbers, sign - and. how can I make a function for it?
I have two input fields, latitude and longitude. In it I should only allow the entry of numbers, sign - and. how can I make a function for it?
Using this function, you can limit the number of keys that the user can type, in their case: numbers, sign ( -
) and period ( .
)
var filtroTeclas = function(event) {
return ((event.charCode >= 48 && event.charCode <= 57) || (event.keyCode == 45 || event.charCode == 46))
}
label {
float: right;
}
<table>
<tr>
<td>
<label for="latitude">Latitude:</label>
</td>
<td>
<input type="text" id="latitude" onkeypress='return filtroTeclas(event)' />
</td>
</tr>
<tr>
<td>
<label for="latitude">Longitude:</label>
</td>
<td>
<input type="text" id="latitude" onkeypress='return filtroTeclas(event)' />
</td>
</tr>
</table>