Created
April 21, 2020 23:30
-
-
Save taciara/33ede3ffd597adc7a89a5437f1f5221b to your computer and use it in GitHub Desktop.
Másca dual para telefone/celular
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
| <!-- no formulário --> | |
| <input type="tel" id="phone" class="phone" name="phone" placeholder="Seu Telefone ou Whatsapp" autocomplete="off" required> | |
| <!-- biblioteca importante --> | |
| <script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script> | |
| <script type="text/javascript" src="assets/js/jquery.mask.js"></script> | |
| <!-- js para funcionar --> | |
| <script type="text/javascript"> | |
| (function($) { | |
| $(function() { | |
| var SPMaskBehavior = function (val) { | |
| return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009'; | |
| }, | |
| spOptions = { | |
| onKeyPress: function(val, e, field, options) { | |
| field.mask(SPMaskBehavior.apply({}, arguments), options); | |
| } | |
| }; | |
| $('.phone').mask(SPMaskBehavior, spOptions); | |
| }); | |
| })(jQuery); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment