Created
April 7, 2017 21:31
-
-
Save juliozuppa/a2ed52d48595e2b1dff8525b2c600ac7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Permite apenas números, vírgula e ponto (000.000.000,00) | |
* Ideal para o evento keypress de um input por exemplo | |
*/ | |
function onlyMonetary(event) { | |
var character = String.fromCharCode(event.keyCode); | |
var regex1 = new RegExp(/[\d.,]/); | |
if (!regex1.test(character)) { | |
if (event.preventDefault) event.preventDefault(); | |
event.returnValue = false; // caso o navegador não aceite preventDefault | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment