Return to Snippet

Revision: 37927
at December 20, 2010 22:44 by webbral


Initial Code
<script type="text/javascript">
function MascaraTEL(campo, teclaPress) {
  if (window.event){
    var tecla = teclaPress.keyCode;
  } else {
    tecla = teclaPress.which;
  }
  var s = new String(campo.value);
  s = s.replace(/(\.|\(|\)|\/|\-| )+/g,'');
  tam = s.length + 1;
  if (tam > 4 && tam < 9)
    campo.value = s.substr(0,4) + '-' + s.substr(4, tam);
}
<script/>

<!--Campo Telefone-->
<input type="text" onkeyup="MascaraTEL(this, event);"/>

Initial URL

                                

Initial Description

                                

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

Initial Tags
javascript, html

Initial Language
JavaScript