Posted By

webbral on 12/20/10


Tagged

javascript html validacao mascara


Versions (?)

Máscara para campo TELEFONE (Mask for the field PHONE)


 / Published in: JavaScript
 

  1. <script type="text/javascript">
  2. function MascaraTEL(campo, teclaPress) {
  3. if (window.event){
  4. var tecla = teclaPress.keyCode;
  5. } else {
  6. tecla = teclaPress.which;
  7. }
  8. var s = new String(campo.value);
  9. s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
  10. tam = s.length + 1;
  11. if (tam > 4 && tam < 9)
  12. campo.value = s.substr(0,4) + '-' + s.substr(4, tam);
  13. }
  14. <script/>
  15.  
  16. <!--Campo Telefone-->
  17. <input type="text" onkeyup="MascaraTEL(this, event);"/>

Report this snippet  

You need to login to post a comment.