Quantcast
Channel: Últimos conteúdos
Viewing all articles
Browse latest Browse all 14190

Validar formulário com mensagem- Jquery

$
0
0

Queria que quando eu apertasse o botão de enviar aparecesse um alerta "Sucesso!". Criei Uma função simples e atribui ao evento onClick, mas aparece uma mensagem mesmo que campos que estejam em branco ou com  quantidade errada de caracteres determinados. Essa Mensagem só deve aparecer quando o formulário for preenchido corretamente.

 

 

<! DOCTYPE html>
<html>
<head>
<title> Validação </ title>
<meta charset = "utf-8">
<link rel = "stylesheet" type = "text / css" href = "../ css / style.css">
<script type = "text / javascript"  src = "../ js / jquery.min.js"> </ script>
<script type = "text / javascript"  src = "../ js / jquery.maskedinput.js"> </ script>
<script type = "text / javascript"  src = "../ js / jquery.validate.js"> </ script>
<script type = "text / javascript">
 
$ (function formulario () {
$ ("# data").mask ("99/99/9999");
 
 
$ ("form#cadastro").validate ({
rules: {
nome: {
required: true,
minlength: 5
 
 
}
 
 
},
messages: {
nome: {
required: "Campo Obrigatório.",
minlength: "O campo DEVE Conter No Mínimo 5 caracteres"
}
 
}
 
 
});
 
return false;
});
function msg () {
 
alert ("Sucesso!");
 
 
}
</ script>
 
 
</ head>
<body>
<form id = "cadastro">
  Nome <br>
<input type = "text"  name = "nome" ><br>
Dados <br>
<input type = "text" name = "data" id = "data"> <br>
 
<input type = "submit"  value = "Cadastro"  onClick = "msg ();"> 
</ form> 
</ body>
</ html> 

Viewing all articles
Browse latest Browse all 14190