Skip to content

Instantly share code, notes, and snippets.

@Javlopez
Created April 27, 2011 16:23
Show Gist options
  • Save Javlopez/944596 to your computer and use it in GitHub Desktop.
Save Javlopez/944596 to your computer and use it in GitHub Desktop.
Filtro simple de numeros floats validos
<script type="text/javascript">
<!--
function filterFloat(evt){
// Backspace = 8, Enter = 13, ‘0′ = 48, ‘9′ = 57, ‘.’ = 46, ‘-’ = 43
var key = window.Event ? evt.which : evt.keyCode;
if(key >= 48 && key <= 57){
return true;
}else{
if(key == 8 || key == 13 || key == 46) {
return true;
}else{
return false;
}
}
}
function filter(input){
var preg = /^([0-9]+\.?[0-9]{0,2})$/;
if(preg.test(input.value) === true){
return true;
}else{
if(input.value!= ""){
alert("Tu numero esta mal solo dos decimales");
input.focus();
return false;
}else{
return true;
}
}
}
-->
</script>
<input type="text" name="moneda nac" id="moneda_nac" value="10" onkeyup="return filter(this);" onkeypress="return filterFloat(event);"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment