5
I have two input fields, latitude and longitude. In it I should only allow the input of numbers, sign - and . how can I make a function for that?
5
I have two input fields, latitude and longitude. In it I should only allow the input of numbers, sign - and . how can I make a function for that?
6
Using this function below you limit the keys that the user can type, in your case: numbers, sign (-
) and point ( .
)
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>
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Response link-> You will have to use input mask
– hoheckell
A
<input type='number'>
does not serve?– Renan Gomes