Skip to content

Instantly share code, notes, and snippets.

@felipeorlando
Last active August 31, 2016 17:08
Show Gist options
  • Save felipeorlando/b217d14b4fdcd603e8b4fc790d21cf12 to your computer and use it in GitHub Desktop.
Save felipeorlando/b217d14b4fdcd603e8b4fc790d21cf12 to your computer and use it in GitHub Desktop.
;(function(){
var $phone = $('.phone');
var init = function () {
maskAll();
};
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);
}
};
var maskAll = function() {
$phone.mask(SPMaskBehavior, spOptions);
}
$(document)
.ready(init)
;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment