Galera preciso de uma ajuda sou iniciante e precisava saber como valido o CPF com numeros e o telefone neste formulario:
<script type="text/javascript">
function valida() {
limpar() ;
var n, i, e , t ,a ;
n = document.form1.txtnome.value ;
c = document.form1.txtcpf.value ;
e = document.form1.txtemail.value ;
t = document.form1.txttelefone.value ;
a = document.form1.txtassunto.value ;
if ( n.length == 0 ) {
alert("Digite o nome") ;
document.form1.txtnome.focus() ;
document.form1.txtnome.style.background="gainsboro" ;
return false ;
}
if ( isNaN(c) || c.length == 0 ) {
alert("Obrigatório o campo CPF") ;
document.form1.txtcpf.focus() ;
document.form1.txtcpf.style.background="gainsboro" ;
document.form1.txtcpf.value = "" ;
return false ;
}
if ( e.indexOf( "@" ) < 0 ) {
alert("Obrigatório o campo e-mail") ;
document.form1.txtemail.focus() ;
document.form1.txtemail.style.background="gainsboro" ;
return false ;
}
if ( t.length == 0 ) {
alert("Obrigatório o campo Telefone") ;
document.form1.txttelefone.focus() ;
document.form1.txttelefone.style.background="gainsboro" ;
return false ;
}
if ( a.length == 0 ) {
alert("Obrigatório o campo Assunto") ;
document.form1.txtassunto.focus() ;
document.form1.txtassunto.style.background="gainsboro" ;
return false ;
}
document.form1.submit() ;
}
function limpar(){
document.form1.txtnome.style.background="white" ;
document.form1.txtcpf.style.background="white" ;
document.form1.txtemail.style.background="white" ;
document.form1.txttelefone.style.background="white" ;
document.form1.txtassunto.style.background="white" ;
}
</script>
</head>
<body>
<form name="form1" method="post" action="grava.jsp" >
<table align="center">
<tr>
<td>Nome:
<td><input type="text" name="txtnome"></td>
</tr>
<tr>
<td>CPF:</td>
<td> <input type="text" name="txtcpf"></td>
</tr>
<tr>
<td> e-mail:</td>
<td><input type="text" name="txtemail"></td>
</tr>
<tr>
<td>Telefone:</td>
<td> <input type="text" name="txttelefone"></td>
</tr>
<tr>
<td>Assunto:</td>
<td> <input type="text" name="txtassunto"></td>
</tr>
<tr> <td>Mensagem:</td>
<td><textarea name="" cols="20" rows="5"></textarea></td>
</tr>
<td></td>
<td> <input type="reset" value="Limpar"/> <input type="button" value="Enviar" onClick="valida()" ></td>
</tr>
</table>
</form>