Jquery Validate does not validate data by Submit method __jquery

Source: Internet
Author: User
Tags curl valid email address

jquery.validate.js automatically validate data when a form (submit) is submitted

$.validator.setdefaults ({submithandler:function () {alert ("submitted!");

	}
	});

		$ (). Ready (function () {//Validate the comment form when it is submitted $ ("#commentForm"). Validate (); Validate signup form on KeyUp and submit $ ("#signupForm"). Validate ({rules: {firstname: "Required", LASTN AME: "Required", Username: {required:true, minlength:2}, Password: {required:true, M Inlength:5}, Confirm_password: {required:true, Minlength:5, Equalto: "#password"}, EM
				AIL: {required:true, email:true}, topic: {Required: "#newsletter: Checked", Minlength:2  }, agree: "Required"}, messages: {firstname: ' Please enter your FirstName ', LastName: ' Please enter Your LastName ", Username: {required:" Please enter a username ", minlength:" Your username must consist of At least 2 characters "}, Password: {required:" please provide a password ", minlength:" Your Password must is at least 5 characters long "}, Confirm_password: { Required: "Please provide a password", minlength: "Your password is at must 5 least long", characters o: "Please enter the same password as above"}, email: ' Please enter a valid email address ', agree: "Please AC

		Cept our Policy "}}); Propose username by combining First-and LastName $ (' #username '). focus (function () {var FirstName = $ ("#firstname"
			). Val ();
			var LastName = $ ("#lastname"). Val ();
			if (FirstName && lastname &&!this.value) {this.value = FirstName + "." + LastName;

		}
		});
		Code to hide topic selection, disable for demo var newsletter = $ ("#newsletter");
		Newsletter topics are optional, hide at a-var inital = newsletter.is (": Checked"); var topics = $ ("#newsletter_topics") [inital?
		"Removeclass": "AddClass"] ("gray"); var topicinputs = topics.find ("input"). attr ("Disabled",!inital); Show as newsletter is checked Newsletter.click (function () {topics[this.checked?
			"Removeclass": "AddClass"] ("gray");
		Topicinputs.attr ("Disabled",!this.checked);
	}); });

<form class= "Cmxform" id= "Commentform" method= "post" action= "/post.php" > <fieldset> &L T;legend>please provide your name, email address (won "t be published) and a comment</legend> <p> ; label for= "CNAME" >name (required, at least 2 characters) </label> <input id= "CNAME" name= "Name" minlength=
				"2" type= "text" required> </p> <p> <label for= "Cemail" >e-mail (required) </label> <input id= "Cemail" type= "email" name= "email" required> </p> <p> <label for= "Curl" >url (o ptional) </label> <input id= "curl" type= "url" name= "url" > </p> <p> <label for= "CCO Mment ">your Comment (required) </label> <textarea id=" ccomment "name=" comment "required></textarea&
			Gt </p> <p> <input class= "Submit" type= "submit" value= "Submit" > </p> </fieldset> & Lt;/form> 

Jquery.validate does not use the form submit method to carry on the data verification

function Jqvalidate ()
{return
	$ (' #formLogin '). Validate ({
		rules:{
			truename: ' Required ',
			Password: ' Required ',
			},
		messages:{
			truename: ' Please enter login username ',
			password: ' Password cannot be empty ',
			}

,} function submitbtn ()
{
	 if (jqvalidate ()) {  
		 $ (' #formLogin '). Submit ();


<form id= "Formlogin" class= "Formlo" autocomplete= "Off" accept-charset= "UTF-8" action= "" method= "POST" >
<div id= "RegForm" >
  <div class= "inputl name" >
	<label>
		<span> user name:</span>
		<input id= "username" class= "input Error" type= "text" value= "" Name= "Truename" placeholder= "" Please enter account ">
	</label>
  </div>
	<div class= "Btns" >
		<a class= "Submit" onclick= "submitbtn ();" href= "Javascript:void (0);" > Login </a>
	</div>
</div>
</form>


Jquery Validate document Address: Https://github.com/DiegoLopesLima/Validate#readme




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.