jQuery-Mask-Plugin
jQuery-Mask-Plugin copied to clipboard
Two mask in the same field, CPF and cell phone
What strategy I can use to perform two mask for the same field, CPF and cell phone? I found one for CPF and CNPJ, but to me doesn't work.
PS: Both, CPF and cell phone, it's the same size.
Para Telefone e Celular no mesmo campo:
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);
}
};
$('.mask-phone').mask(SPMaskBehavior, spOptions);