Created
June 25, 2014 21:50
-
-
Save ricardodantas/8852e5e21191b5780cf8 to your computer and use it in GitHub Desktop.
Jquery Mask for brazilian pattern phone fields. From http://www.williamokano.com/2013/09/mascara-jquery-telefone-nono-9o-digito/
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
| jQuery.fn.brTelMask = function() { | |
| return this.each(function(){ | |
| var el = this; | |
| $(el).focus(function(){ | |
| $(el).mask("(99) 9999-9999?9"); | |
| }); | |
| $(el).focusout(function(){ | |
| var phone, element; | |
| element = $(el); | |
| element.unmask(); | |
| phone = element.val().replace(/\D/g, ''); | |
| if(phone.length > 10){ | |
| element.mask("(99) 99999-999?9"); | |
| }else{ | |
| element.mask("(99) 9999-9999?9"); | |
| } | |
| }); | |
| }); | |
| } | |
| $(document).ready(function() { | |
| $(".campo-telefone").brTelMask(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment