I tried to create a simple mask for my form, but the landline is not returning as expected.
Code:
function formatar(mascara, documento){
var i = documento.value.length;
var saida = mascara.substring(0,1);
var texto = mascara.substring(i)
if (texto.substring(0,1) != saida){
documento.value += texto.substring(0,1);
}
}
<label for="Cep"> CEP: </label>
<input type="text" size="8" id="Cep" maxlength="9" OnKeyPress="formatar('#####-###', this)">
<br>
<label id="data">Data de Nascimento:</label>
<label for="Cdata"></label>
<input type="text" name="data" id="data" size="9" maxlength="10" OnKeyPress="formatar('##/##/####', this)">
<br>
<label for="Cpf"> CPF:</label>
<input type="text" id="Cpf" size="12" maxlength="14" OnKeyPress="formatar('###.###.###-##', this)"/>
<br>
<label for="Crg"> RG:</label>
<input type="text" name="Trg" id="Crg" size="12" maxlength="14" OnKeyPress="formatar('##.###.###-##', this)">
<br>
<label for="TelF"> Tel Fixo</label>
<input type="text" name="fTel" id="TelF" size="14" maxlength="14" OnKeyPress="formatar('(##) ####-####', this)">
Result: