Skip to content

Instantly share code, notes, and snippets.

@alexlatam
Forked from Javlopez/filter.html
Created April 21, 2021 21:42
Show Gist options
  • Save alexlatam/e4ffcdf88fa1ecb38e65819dcc439fe9 to your computer and use it in GitHub Desktop.
Save alexlatam/e4ffcdf88fa1ecb38e65819dcc439fe9 to your computer and use it in GitHub Desktop.
Solo numeros con 1 punto y maximo dos decimales
<script type="text/javascript">
<!--
function filterFloat(evt,input){
// Backspace = 8, Enter = 13, ‘0′ = 48, ‘9′ = 57, ‘.’ = 46, ‘-’ = 43
var key = window.Event ? evt.which : evt.keyCode;
var chark = String.fromCharCode(key);
var tempValue = input.value+chark;
if(key >= 48 && key <= 57){
if(filter(tempValue)=== false){
return false;
}else{
return true;
}
}else{
if(key == 8 || key == 13 || key == 0) {
return true;
}else if(key == 46){
if(filter(tempValue)=== false){
return false;
}else{
return true;
}
}else{
return false;
}
}
}
function filter(__val__){
var preg = /^([0-9]+\.?[0-9]{0,2})$/;
if(preg.test(__val__) === true){
return true;
}else{
return false;
}
}
-->
</script>
<input type="text" name="moneda nac" id="moneda_nac" value="10" onkeypress="return filterFloat(event,this);"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment