Source: A Plug-in by Igor Escobar on Github.
Last active
July 23, 2024 16:51
-
-
Save vinicius-stutz/6caf02d4936069c69513 to your computer and use it in GitHub Desktop.
Máscara p/ telefones com 8 ou 9 dígitos (jquery.mask.js)
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Máscaras de telefone (Brasil)</title> | |
<script type='text/javascript' src='//code.jquery.com/jquery-compat-git.js'></script> | |
<script type='text/javascript' src='//igorescobar.github.io/jQuery-Mask-Plugin/js/jquery.mask.min.js'></script> | |
</head> | |
<body> | |
<p> | |
<label> | |
Máscara para campo já com máscara<br /> | |
<input type="text" class="phone" value="(21) 12345-6789" /> | |
</label> | |
</p> | |
<p> | |
<label> | |
Máscara para campo SOMENTE números<br /> | |
<input type="text" class="phone" value="21123456789" /> | |
</label> | |
</p> | |
</body> | |
</html> |
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
var behavior = function (val) { | |
return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009'; | |
}, | |
options = { | |
onKeyPress: function (val, e, field, options) { | |
field.mask(behavior.apply({}, arguments), options); | |
} | |
}; | |
$('.phone').mask(behavior, options); |
Funcionou com perfeição. Muito obrigado!
Boa!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Vlw irmão, eu tava aqui deitado no chão em posição fetal, chorando, usando o jQueryInputMask