myers Posted August 8, 2004 Report Share Posted August 8, 2004 Gostaria de saber como posso colocar mascaras em campos INPUT's tipo quando a pessoa for digitar a data de nascimento dela: 20/08/1966 ela não precise digitar as barras mesma coisa no RG 34.356.555-9 onde ela apenas digitaria os numeros Quote Link to comment Share on other sites More sharing options...
0 Deividy Posted August 8, 2004 Report Share Posted August 8, 2004 você vai ser melhor atendido no javascript vou te mover pra lá Quote Link to comment Share on other sites More sharing options...
0 Illidan Posted August 8, 2004 Report Share Posted August 8, 2004 Tem um código postado na seção de scripts que faz isso... dá uma olhada por lá. Até mais! Quote Link to comment Share on other sites More sharing options...
0 --_Michel_-- Posted August 11, 2004 Report Share Posted August 11, 2004 Tenta esse...<html> <head> <title>Máscaras para Formulários</title> <script language="JavaScript"> /*** * Descrição.: formata um campo do formulário de * acordo com a máscara informada... * Parâmetros: - objForm (o Objeto Form) * - strField (string contendo o nome * do textbox) * - sMask (mascara que define o * formato que o dado será apresentado, * usando o algarismo "9" para * definir números e o símbolo "!" para * qualquer caracter... * - evtKeyPress (evento) * Uso.......: <input type="textbox" * name="xxx"..... * onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);"> * Observação: As máscaras podem ser representadas como os exemplos abaixo: * CEP -> 99.999-999 * CPF -> 999.999.999-99 * CNPJ -> 99.999.999/9999-99 * Data -> 99/99/9999 * Tel Resid -> (99) 999-9999 * Tel Cel -> (99) 9999-9999 * Processo -> 99.999999999/999-99 * C/C -> 999999-! * E por aí vai... ***/ function txtBoxFormat(objForm, strField, sMask, evtKeyPress) { var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla; if(document.all) { // Internet Explorer nTecla = evtKeyPress.keyCode; } else if(document.layers) { // Nestcape nTecla = evtKeyPress.which; } sValue = objForm[strField].value; // Limpa todos os caracteres de formatação que // já estiverem no campo. sValue = sValue.toString().replace( "-", "" ); sValue = sValue.toString().replace( "-", "" ); sValue = sValue.toString().replace( ".", "" ); sValue = sValue.toString().replace( ".", "" ); sValue = sValue.toString().replace( "/", "" ); sValue = sValue.toString().replace( "/", "" ); sValue = sValue.toString().replace( "(", "" ); sValue = sValue.toString().replace( "(", "" ); sValue = sValue.toString().replace( ")", "" ); sValue = sValue.toString().replace( ")", "" ); sValue = sValue.toString().replace( " ", "" ); sValue = sValue.toString().replace( " ", "" ); fldLen = sValue.length; mskLen = sMask.length; i = 0; nCount = 0; sCod = ""; mskLen = fldLen; while (i <= mskLen) { bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/")) bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ")) if (bolMask) { sCod += sMask.charAt(i); mskLen++; } else { sCod += sValue.charAt(nCount); nCount++; } i++; } objForm[strField].value = sCod; if (nTecla != 8) { // backspace if (sMask.charAt(i-1) == "9") { // apenas números... return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9 else { // qualquer caracter... return true; } } else { return true; } } //Fim da Função Máscaras Gerais </script> </head> <body> <font size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Formatação de várias Máscaras de Entradas para campos de Formulários</strong></font> <form name="Form"> <table border="0" cellspacing="2" cellpadding="2"> <tr> <td width="66"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Cep </font></td> <td width="128"> <input type="text" name="str_cep" maxlength="10" size="10" onKeyPress="return txtBoxFormat(document.Form, 'str_cep', '99.999-999', event);"> </td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">CPF</font></td> <td> <input type="text" name="str_cpf" maxlength="14" size="14" onKeyPress="return txtBoxFormat(document.Form, 'str_cpf', '999.999.999 99', event);"> </td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">CNPJ</font></td> <td><input type="text" name="str_cnpj" maxlength="18" size="18" onKeyPress="return txtBoxFormat(document.Form, 'str_cnpj', '99.999.999/9999-99', event);"></td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Data</font></td> <td><input type="text" name="str_data" maxlength="10" size="10" onKeyPress="return txtBoxFormat(document.Form, 'str_data', '99/99/9999', event);"></td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Tel Residencial</font></td> <td><input type="text" name="str_tel2" maxlength="14" size="14" onKeyPress="return txtBoxFormat(document.Form, 'str_tel2', '(99) 9999-9999', event);"></td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Tel Celular </font></td> <td> <input type="text" name="str_tel" maxlength="14" size="14" onKeyPress="return txtBoxFormat(document.Form, 'str_tel', '(99) 9999-9999', event);"> </td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Processo</font></td> <td><input type="text" name="str_proc" maxlength="20" size="20" onKeyPress="return txtBoxFormat(document.Form, 'str_proc', '99.999999999/9999-99', event);"></td> </tr> <tr> <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Conta </font></td> <td> <input type="text" name="str_cc" maxlength="6" size="10" onKeyPress="return txtBoxFormat(document.Form, 'str_cc', '9999-!', event);"> </td> </tr> </table> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
0 Mutuka Posted August 11, 2004 Report Share Posted August 11, 2004 Uma dica RG e diferente, osu combinaçao diferente em outros estados, agora cep CIC iguais em qualquer lugar Quote Link to comment Share on other sites More sharing options...
Question
myers
Gostaria de saber como posso colocar mascaras em campos INPUT's tipo quando a pessoa for digitar a data de nascimento dela: 20/08/1966 ela não precise digitar as barras mesma coisa no RG 34.356.555-9 onde ela apenas digitaria os numeros
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.