Skip to content

Instantly share code, notes, and snippets.

@Javlopez
Created April 27, 2011 17:46
Show Gist options
  • Save Javlopez/944773 to your computer and use it in GitHub Desktop.
Save Javlopez/944773 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);"/>
@jrodrigo93
Copy link

Alguien sabe como editar el monto sin tener que borrar todo el contenido del input y volver a digitar el valor?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment