function FormataData(objeto,teclapress) { var tecla = teclapress.keyCode; //Testa se o campo está selecionado, se estiver, limpa o conteúdo para nova digitação. var selecionado = document.selection.createRange(); var selecao = selecionado.text; if((selecao != "") && (tecla != 8) && (tecla != 9) && (tecla != 13) && (tecla != 35) && (tecla != 36) && (tecla != 46) && (tecla != 16) && (tecla != 17) && (tecla != 18) && (tecla != 20) && (tecla != 27) && (tecla != 37) && (tecla != 38) && (tecla != 39) && (tecla != 40)) {objeto.value = "";} if(((window.event.keyCode == 13) || (window.event.keyCode == 9))&&objeto.value != "") { if(!(ValidaData(objeto))) { window.event.cancelBubble = true; window.event.returnValue = false; alert("Data Inválida"); objeto.value = ""; objeto.focus(); } } if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )&& objeto.value.length < (10)) { vr = objeto.value; vr = vr.replace( "/", "" ); vr = vr.replace( "/", "" ); tam = vr.length; if (tam < 8) { if (tecla != 8) {tam = vr.length + 1 ;} } else { window.event.cancelBubble = true; window.event.returnValue = false; } if ((tecla == 8) && (tam > 1)) { tam = tam - 1 ; objeto.value = vr.substr(0,tam); window.event.cancelBubble = true; window.event.returnValue = false; } if ( tam <= 4 && tecla != 8){ objeto.value = vr ; } if ( (tam >= 4) && (tam <= 6) ){ objeto.value = vr.substr(0, tam - 4) + '/' + vr.substr( tam - 4, 4 ); } if ( (tam >= 6) && (tam <= 8) ){ objeto.value = vr.substr(0, tam - 6 ) + '/' + vr.substr( tam - 6, 2 ) + '/' + vr.substr( tam - 4, 4 ); } if ((tam == (8)) && tecla != 8) { if(tecla >=96 && tecla <=105) { tecla = tecla - 48; } objeto.value = objeto.value + (String.fromCharCode(tecla)); window.event.cancelBubble = true; window.event.returnValue = false; if (!(ValidaData(objeto))) { alert("Data Inválida"); objeto.value = ""; objeto.focus(); } } } else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46)) { event.returnValue = false; } } no campo da tada vc coloca onKeyDown="FormataData(this,event);"