我需要在“Masked Input Plugin”中执行一个实现,以使其工作接受以下值的掩码:
(99) 9999-9999 or (99) 99999-9999
我试过这个:
$('.tel').mask('(99) 9999? 9-9999');
但是如果我在呈现 (99) 99999-999
时报告值 (99) 9999 9999
我不想要
最佳答案
你可以使用这个不错的解决方案
$('.tel').focusout(function(){
var phone, element;
element = $(this);
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");
}
}).trigger('focusout');
原始代码位于
http://pedroelsner.com/2012/07/mascara-jquery-para-novo-digito-de-celular-em-sao-paulo/
关于javascript - 屏蔽输入插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9146331/