Ir para conteúdo
Fórum Script Brasil
  • 0

validação de campos


ju_rezende

Pergunta

bom dia pessoal estou eu aqui mais uma vez com um problemão de validação de campos.

Preciso validar campos de e-mail, cpf, data, sexo (radiobuton), cep, campos numéricos, então como não entendo muito de java, comecei a pesquisar na net, e achei algumas coisas porém, no exemplo que baixei a validação de cpf funcina certinho, mas quando coloque em minha página ele é pulado, o mesmo ocorre com validação de e-mail, ainda nem cheguei na validação de data e cep, campos numéricos.

Vou postar meu código aqui, caso alguém possa me ajudar, fico grata pela atenção de todos.

Scrip

<script language="JavaScript">

function validaForm(){

//validar nome

d = document.cadastro;

var expressao = /([0-1]{1}[0-9]{1}|[0-2]{1}[0-4]{1})\:[0-5]{1}[0-9]{1}/;

if (d.nome.value == ""){

alert("O campo nome completo do formulário deve ser preenchido!");

d.nome.focus();

return false;

}

if (d.cpf.value == ""){

alert("O campo CPF do formulário deve ser preenchido!");

d.cpf.focus();

return false;

}

if (d.endereco.value == ""){

alert("O campo endereço do formulário deve ser preenchido!");

d.endereco.focus();

return false;

}

if (d.bairro.value == ""){

alert("O campo bairro do formulário deve ser preenchido!");

d.bairro.focus();

return false;

}

if (d.cidade.value == ""){

alert("O campo cidade do formulário deve ser preenchido!");

d.cidade.focus();

return false;

}

if (d.UF.value == ""){

alert("O campo estado do formulário deve ser preenchido!");

d.UF.focus();

return false;

}

if (d.cep.value == ""){

alert("O campo CEP do formulário deve ser preenchido!");

d.cep.focus();

return false;

}

if (d.ddd.value == ""){

alert("O campo DDD residencial do formulário deve ser preenchido!");

d.ddd.focus();

return false;

}

if (d.tel.value == ""){

alert("O campo telefone residencial do formulário deve ser preenchido!");

d.tel.focus();

return false;

}

if (d.dddCel.value == ""){

alert("O campo DDD do celular do formulário deve ser preenchido!");

d.dddCel.focus();

return false;

}

if (d.cel.value == ""){

alert("O campo celular do formulário deve ser preenchido!");

d.cel.focus();

return false;

}

if (d.email.value == ""){

alert("Informe seu e-mail.");

d.email.focus();

d.email.select();

return false;

} else {

prim = d.email.value.indexOf("@")

if(prim < 2) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf("@",prim + 1) != -1) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf(".") < 1) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf(" ") != -1) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf("zipmeil.com") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf("hotmeil.com") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf(".@") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf("@.") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf(".com.br.") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf("/") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf("[") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf("]") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf("(") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf(")") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

if(d.email.value.indexOf("..") > 0) {

alert("O e-mail informado parece não estar correto.");

d.email.focus();

d.email.select();

return false;

}

}

if (d.emai1.value == ""){

alert("O campo repetir e-mail do formulário deve ser preenchido!");

d.emai1.focus();

return false;

}

if (d.nascimento.value == ""){

alert("O campo data de nascimento do formulário deve ser preenchido!");

d.nascimento.focus();

return false;

}

if (d.senha.value == ""){

alert("O campo senha do formulário deve ser preenchido!");

d.senha.focus();

return false;

}

if (d.senha1.value == ""){

alert("O campo repetir senha do formulário deve ser preenchido!");

d.senha1.focus();

return false;

}

senha1 = document.cadastro.senha.value

senha2 = document.cadastro.senha1.value

if (senha1 != senha2){

alert("Senhas Diferentes");

return false;

}

email1 = document.cadastro.email.value

email2 = document.cadastro.emai1.value

if (email1 != email2){

alert("E-mails Diferentes");

return false;

}

return true;

}

</script>

<script language="javascript">

function VerificaCPF () {

if (vercpf(document.cadastro.cpf.value))

{document.cadastro.submit();}else

{errors="1";if (errors) alert('CPF NÃO VÁLIDO');

document.retorno = (errors == '');}}

function vercpf (cpf)

{if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999")

return false;

add = 0;

for (i=0; i < 9; i ++)

add += parseInt(cpf.charAt(i)) * (10 - i);

rev = 11 - (add % 11);

if (rev == 10 || rev == 11)

rev = 0;

if (rev != parseInt(cpf.charAt(9)))

return false;

add = 0;

for (i = 0; i < 10; i ++)

add += parseInt(cpf.charAt(i)) * (11 - i);

rev = 11 - (add % 11);

if (rev == 10 || rev == 11)

rev = 0;

if (rev != parseInt(cpf.charAt(10)))

return false;

alert('O CPF INFORMADO É VÁLIDO.');return true;}

</script>

meu form

<form name="cadastro" action="ConfirmaCadastro.asp" method="post" onSubmit="return validaForm();return VerificaCPF();">
                          <tr>
                            <td width="505" height="35" background="images/bg_lista_02.gif" alt=""><!-- incio botoes sua conta -->
                              <!-- fim botoes sua conta -->
                              <span class="style19"><img src="images/transp.gif" alt="" width="10" height="1" />
                              Ainda N&atilde;o Sou Cadastrado</span></td>
                          </tr>
                            <tr>
                            <td width="505" height="50" align="left" valign="top" class="style29" alt="">
                        <table width="505" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                          <td width="20"></td>
                            <td>Se voc&ecirc; ainda n&atilde;o &eacute; cliente, 
                            por favor preencha os campos abaixo. Sua privacidade &eacute; garantida.<br />
                        (<span class="style5">*</span>) campo obrigat&oacute;rio.</td>
                          </tr>
                        </table>
                            </td>
                          </tr>
                          <tr>
                            <td width="505" height="4" alt=""></td>
                          </tr>
                          <tr>
                            <td width="505" height="24" background="images/bg_lista_03.gif" alt="">
                            <img src="images/transp.gif" alt="" width="15" height="1" /><span class="style4">
                            DADOS PESSOAIS: 
                            
                            </span></td>
                          </tr>
                          <tr>
                            <td width="505" alt=""><!-- inico campos dados -->
                                <table  width="505" height="435" border="0" cellpadding="0" cellspacing="0">
                                
                                  <tr>
                                    <td width="119" height="5" alt=""></td>
                                    <td width="386" height="5" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" class="style8" alt="">
                                    <span class="style29">Nome Completo:</span><span class="style5">*</span></td>
                                    <td width="386" height="20" alt=""><span class="style4">
                                      <input name="nome" type="text" size="55" />
                                    </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="6" alt=""></td>
                                    <td width="386" height="6" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" alt="">
                                    <span class="style29">CPF:</span><span class="style8"><span class="style5">*</span></span></td>
                                    <td width="386" height="20" alt=""><span class="style4">
                                      <input name="cpf" type="text" size="30" maxlength="11" />
                                    apenas n&uacute;meros </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="6" alt=""></td>
                                    <td width="386" height="6" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" alt="">
                                    <span class="style29">Endere&ccedil;o:</span><span class="style8">
                                    <span class="style5">*</span></span></td>
                                    <td width="386" height="20" alt=""><span class="style4">
                                      <input name="endereco" type="text" size="55" />
                                    </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="23" align="right" valign="middle" alt=""></td>
                                    <td width="386" height="23" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" alt="">
                                    <span class="style29">Complemento</span>
                                    <span class="style29">:</span></td>
                                    <td width="386" height="20" alt=""><span class="style4">
                                      <input name="complemento" type="text" size="55" />
                                    </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="6" alt=""></td>
                                    <td width="386" height="6" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" alt="">
                                    <span class="style29">Bairro:</span><span class="style8">
                                    <span class="style5">*</span></span></td>
                                    <td width="386" height="20" alt=""><span class="style4">
                                      <input name="bairro" type="text" size="55" />
                                    </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="6" alt=""></td>
                                    <td width="386" height="6" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" alt="">
                                    <span class="style29">Cidade:</span>
                                    <span class="style8"><span class="style5">*</span></span></td>
                                    <td width="386" height="20" alt=""><span class="style4">
                                      <input name="cidade" type="text" size="55" />
                                    </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="5" alt=""></td>
                                    <td width="386" height="5" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="22" align="right" valign="middle" alt="">
                                    <span class="style29">Estado:</span>
                                    <span class="style8"><span class="style5">*</span></span></td>
                                    <td width="386" height="22" alt=""><span class="style4">
                                      <select name=UF>
                                                                    <option value="AC">AC</option>
                                                                    <option value="AL">AL</option>
                                                                    <option value="AM">AM</option>
                                                                    <option value="AP">AP</option>
                                                                    <option value="BA">BA</option>
                                                                    <option value="CE">CE</option>
                                                                    <option value="DF">DF</option>
                                                                    <option value="ES">ES</option>
                                                                    <option value="GO">GO</option>
                                                                    <option value="MA">MA</option>
                                                                    <option value="MG">MG</option>
                                                                    <option value="MS">MS</option>
                                                                    <option value="muito">muito</option>
                                                                    <option value="PA">PA</option>
                                                                    <option value="PB">PB</option>
                                                                    <option value="PE">PE</option>
                                                                    <option value="PI">PI</option>
                                                                    <option value="PR">PR</option>
                                                                    <option value="RJ">RJ</option>
                                                                    <option value="RN">RN</option>
                                                                    <option value="RO">RO</option>
                                                                    <option value="RR">RR</option>
                                                                    <option value="RS">RS</option>
                                                                    <option value="SC">SC</option>
                                                                    <option value="SE">SE</option>
                                                                    <option value="SP">SP</option>
                                                                    <option value="TO">TO</option>
                                            </select>
                                    </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="5" alt=""></td>
                                    <td width="386" height="5" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" alt="">
                                    <span class="style29">CEP</span>
                                    <span class="style8">:<span class="style5">*</span></span></td>
                                    <td width="386" height="20" alt=""><span class="style4">
                                      <input name="cep" type="text" size="30" maxlength="8" />
                                    apenas n&uacute;meros </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="26" alt=""></td>
                                    <td width="386" height="26" class="style26" alt="">N&atilde;o sabe o CEP? Clique aqui</td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" alt="">
                                    <span class="style29">Telefone resid.</span><span class="style8">:
                                    <span class="style5">*</span></span></td>
                                    <td width="386" height="20" alt=""><span class="style4">
                                      ddd: 
                                          <input name="ddd" type="text" size="5" />
                                            tel:                                      
                                            <input name="tel" type="text" size="20" />
                                    apenas n&uacute;meros </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="6" alt=""></td>
                                    <td width="386" height="6" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" alt="">
                                    <span class="style29">Celular</span><span class="style8">:
                                    <span class="style5">*</span></span></td>
                                    <td width="386" height="20" alt=""><span class="style4">ddd:
                                        <input name="dddCel" type="text" size="5" />
                                        cel:
                                        <input name="cel" type="text" size="20" />
                                    apenas n&uacute;meros </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="6" alt=""></td>
                                    <td width="386" height="6" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="20" align="right" valign="middle" alt="">
                                    <span class="style29">E-Mail</span>
                                    <span class="style8">:<span class="style5">*</span></span></td>
                                    <td width="386" height="20" alt=""><span class="style4">
                                      <input name="email" type="text" size="55" />
                                    </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="25" align="right" valign="middle" alt="">
                                    <span class="style29">Repetir E-Mail</span><span class="style8">:
                                    <span class="style5">*</span></span></td>
                                    <td width="386" height="25" alt=""><span class="style4">
                                      <input name="emai1" type="text" size="55" />
                                    </span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="22" align="right" valign="middle" alt="">
                                    <span class="style29">Sexo</span><span class="style8">:
                                    <span class="style5">*</span></span></td>
                                    <td width="386" height="22" alt=""><input name="sexo" type="radio" value="f" />
                                        Feminino
                                          <input name="sexo" type="radio" value="m" />
                                        Maculinno                                    </td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="4" alt=""></td>
                                    <td width="386" height="4" alt=""></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="22" align="right" valign="middle" alt="">
                                    <span class="style29">Data de Nascimento</span><span class="style8">:
                                    <span class="style5">*</span></span></td>
                                    <td width="386" height="22" alt=""><span class="style4">
                                      <input name="nascimento" type="text" size="20" maxlength="10" />
dd/mm/aaaa</span></td>
                                  </tr>
                                  <tr>
                                    <td width="119" height="40" alt=""></td>
                                    <td width="386" height="40" alt=""></td>
                                  </tr>
                                </table>
                              <!-- fim campos dados -->
                            </td>
                          </tr>
                          <tr>
                            <td width="505" height="20" background="images/bg_lista_03.gif" alt="">
                            <img src="images/transp.gif" alt="" width="15" height="1" />
                            <span class="style4">SENHA:</span></td>
                          </tr>
                          <tr>
                            <td width="505" height="54" alt=""><table  width="505" border="0" cellpadding="0" cellspacing="0">
                              <tr>
                                <td width="122" height="5" alt=""></td>
                                <td width="383" height="5" alt=""></td>
                              </tr>
                              <tr>
                                <td width="122" height="20" align="right" valign="middle" class="style8" alt="">
                                <span class="style29">Senha:</span>
                                <span class="style5">*</span></td>
                                <td width="383" height="20" alt=""><span class="style4">
                                  <input name="senha" type="password" size="55" maxlength="20" />
                                </span></td>
                              </tr>
                              <tr>
                                <td width="122" height="6" alt=""></td>
                                <td width="383" height="6" alt=""></td>
                              </tr>
                              <tr>
                                <td width="122" height="20" align="right" valign="middle" alt="">
                                <span class="style29">Repetir Senha :</span>
                                <span class="style8"><span class="style5">*</span></span></td>
                                <td width="383" height="20" alt=""><span class="style4">
                                  <input name="senha1" type="password" size="55" maxlength="20" />
                                </span></td>
                              </tr>
                            </table></td>
                          </tr>
                          <tr>
                            <td width="505" height="20" background="images/bg_lista_03.gif" alt="">
                            <img src="images/transp.gif" alt="" width="15" height="1" />
                            <span class="style4">ENDERE&Ccedil;O PARA ENTREGA:</span></td>
                          </tr>
                          <tr>
                            <td width="505" height="61" alt="">&nbsp;</td>
                          </tr>
                          <tr>
                            <td width="505" height="19" align="center" valign="middle" alt="">
                                <input name="image" type="image"   src="images/bot_continuar.gif" alt= "Continuar" img="img"  />
                            </td>
                          </tr>
                          </form>

Grande abraço

Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

eu testei o código aqui... o unico problema que encontrei foi com a validação dos radio buttons para selecionar o sexo... e isso porque um deles já vem selecionado por padrão...

fora isso todos os outros campos obrigatórios estão sendo validados corretamente...

qual o problema real ?

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,3k
    • Posts
      652,3k
×
×
  • Criar Novo...