Skip to content

Instantly share code, notes, and snippets.

@igorescobar
Created September 14, 2012 20:35
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save igorescobar/3724610 to your computer and use it in GitHub Desktop.
Save igorescobar/3724610 to your computer and use it in GitHub Desktop.
Mascara Javascript para os novos telefones de São Paulo
// using: https://github.com/igorescobar/jQuery-Mask-Plugin
var phone_fields, phone_mask;
phone_fields = $(".phone", scope);
phone_mask = /^(\(?11\)? ?9(5[0-9]|6[0-9]|7[01234569]|8[0-9]|9[0-9])[0-9]{1})/g;
phone_fields.each(function() {
var mask, phone_field;
phone_field = $(this);
mask = phone_field.val().match(phone_mask) ? '(00) 00000-0000' : '(00) 0000-0000';
return phone_field.mask(mask, {
onKeyPress: function(phone, e, currentField, options) {
if (phone.match(phone_mask)) {
return $(currentField).mask('(00) 00000-0000', options);
} else {
return $(currentField).mask('(00) 0000-0000', options);
}
}
});
});
Copy link

ghost commented Mar 28, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment