Skip to content

Instantly share code, notes, and snippets.

@Godoy
Created May 5, 2016 16:46
Show Gist options
  • Save Godoy/0291b55ad47161c68a222232e9981e9c to your computer and use it in GitHub Desktop.
Save Godoy/0291b55ad47161c68a222232e9981e9c to your computer and use it in GitHub Desktop.
jquery mask phone telefone 9 digitos
// https://github.com/igorescobar/jQuery-Mask-Plugin/tree/master/dist
$(function () {
$('.phone').mask(PhoneMaskBehavior, spOptions);
});
var PhoneMaskBehavior = function (val) {
return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
},
spOptions = {
onKeyPress: function (val, e, field, options) {
field.mask(PhoneMaskBehavior.apply({}, arguments), options);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment