Created
August 8, 2014 14:18
-
-
Save diegogurgel/38c543f63161edcf5ff9 to your computer and use it in GitHub Desktop.
Função javascript para máscaras(CNPJ, CPF, RG, Telefone)
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
| mask("###.###.###-##","12345678900"); | |
| mask("##.###.###/####-##","12345678000122"); | |
| function mask (pattern,value) { | |
| var result=""; | |
| var lacCount=-1; | |
| for(var i=0, max = pattern.length; i< max;i++){ | |
| if(pattern.charAt(i)==='#'){ | |
| lacCount++; | |
| result+=value[lacCount]; | |
| }else{ | |
| result+=pattern.charAt(i); | |
| } | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment