Jump to content

[Resolvido] Formulário


Elite_R3S

Recommended Posts

vou dar 1 vista de olhos dame apenas 1 momento

falta 1 "}" num dos else if.... mas n da na msm o.0

ta a funcionar agora....

problemas:

falta campo de bi

e tinha mail e na function tinha correio

<html>
<head>
	<script type="text/JavaScript">
		function valida(){
			var mensagem="";
			if(document.formulario.nome.value.length == 0){
				mensagem=mensagem+"Introduza o nome!\n";
			}
			if(document.formulario.contribuinte.value.length < 9){
				mensagem=mensagem+"Escreva todos os digitos do Contribuinte\n";
			}
			else if (isNaN(document.formulario.contribuinte.value)){
				mensagem=mensagem + "O Contribuinte deve ter apenas algarismos. \n";
			}
			if(document.formulario.bi.value.length < 7){
				mensagem=mensagem+"Escreva todos os digitos do BI\n";
			}
			else if (isNaN(document.formulario.bi.value)){
				mensagem=mensagem + "O BI deve ter apenas algarismos. \n";
			}
			if(document.formulario.ano.value.length > 4){
				mensagem=mensagem+ "Introduza o ano \n";
			}
			else if (isNaN(document.formulario.ano.value)){
				mensagem= mensagem+ "O ano deve ter apenas algarismos\n";
			}
			else if (document.formulario.ano.value <= 1900){
				mensagem = mensagem + "O ano deve ser posterior a 1900\n";
			}
			if (document.formulario.mes.value.length != 2){
				mensagem=mensagem + "Introduza os 2 caracteres do mês\n";
			}
			else if (document.formulario.mes.value < 1 || document.formulario.mes.value > 12 ) {
				mensagem = mensagem + "O mês tem que estar entre 01 e 12 \n";
			}
			if (document.formulario.dia.value.length != 2){
				mensagem = mensagem + "Introduza os 2 caracteres do dia\n";
			}
			else if (document.formulario.dia.value < 1 || document.formulario.mes.value > 31 ) {
				mensagem = mensagem + "O mês tem que estar entre 01 e 31 dias \n";
			}
			if (document.formulario.mail.value.indexOf("@") == -1){
				mensagem = mensagem + "Endereço de correio errado \n";
			}
			if (mensagem.length > 0){
				alert (mensagem);
				return false;
			} else {
				return true;
			}
		}
	</script>
</head>
<body>
	<form name="formulario" onsubmit="valida();">	
          		Nome: <input type="text" name="nome"><br>
  		Número de Contribuinte: <input type="num" name="contribuinte" size="9"><br>
  		bi: <input type="num" name="bi" size="9"><br>
  		Data de Nascimento: <br>
  		Ano: <input type="text" name="ano" size="4">
  		Mês: <input type="text" name="mes" size="2">
  		Dia: <input type="text" name="dia" size="2"><br>
  		E-mail: <input type="text" name="mail"><br>
  		<input type="reset" value="Limpar">
  		<input type="submit" value="Confirmar">
        	</form>		 			
</body>
</html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.