Created
April 27, 2011 16:23
-
-
Save Javlopez/944596 to your computer and use it in GitHub Desktop.
Filtro simple de numeros floats validos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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