tenho um script que bloqueia letras e formata o telefone de acordo com o digitado ..
Ex: (61) 3333-3333
Porém tem um erro, se alguém copiar somente o telefone de algum lugar, (notepad, etc) digamos sem o DDD (3333-3333) o campo não formata, fica assim >> (33333333 e teria que ficar assim + ou - (33)33-33 ...com faço pra acrescentar algo assim na minha função?
Pergunta
tonzinhu
iae galera,
tenho um script que bloqueia letras e formata o telefone de acordo com o digitado ..
Ex: (61) 3333-3333
Porém tem um erro, se alguém copiar somente o telefone de algum lugar, (notepad, etc) digamos sem o DDD (3333-3333) o campo não formata, fica assim >> (33333333 e teria que ficar assim + ou - (33)33-33 ...com faço pra acrescentar algo assim na minha função?
function getKeyCode(e) { if (window.event) return window.event.keyCode; else if (e) return e.which; else return null; } function keyRestrict(e, validchars) { // v3.0 var key=", keychar="; key = getKeyCode(e); if (key == null) return true; keychar = String.fromCharCode(key); keychar = keychar.toLowerCase(); validchars = validchars.toLowerCase(); if (validchars.indexOf(keychar) != -1) return true; if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 ) return true; return false; } function mascaraTel(tel){ if(tel.value.length == 0){ tel.value += '('; } if(tel.value.length == 3){ tel.value += ')'; } if(tel.value.length == 8){ tel.value += '-'; } }vlw
Link para o comentário
Compartilhar em outros sites
8 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.