$ ("#myform"). Validate ({debug:true,//Debug mode cancels the default submit feature for SubmitIgnore: ' #Password, #ConfirmPassword ', Focusinvalid:false, //---------------------------------------------------------------------------Submithandler:function() {//form submission handle, as a callback function varSubmitway = $ ("#submitbtn"). text (); if(Submitway = = "Edit Save") varGeturl = "/membership/update"; Else if(Submitway = = "Add Save") varGeturl = "/membership/add"; varOptions ={type:"POST", Url:geturl, DataType:"JSON", Data: $ ("#myform"). Serialize (), Success:function(data) {if(data.success) {alert (data.messages); $("#AddMembership"). Modal (' Hide '); Window.parent.location.reload (); } Elsealert (data.messages); } }; $.ajax (options); return false; }, //--------------------------------------------------------------------------- rules: {' Email ': {required:true, Email:true }, ' UserName ': {required:true, Stringcheck:true, minlength:3, MaxLength:20 }, ' Mobile ':{ //required:true,//With no sentence to indicate that this item does not fill also can, if fill in will check fill in the RulesIsMobile:true }, ' Password ': {required:true, minlength:6, MaxLength:20 }, ' ConfirmPassword ': {required:true, minlength:6, Equalto:"#Password" }, ' RoleName ': {required:true }, ' IsApproved ': {required:true }, ' Gender ': {required:true}}, messages: {UserName: { Required:"Please fill in User name", Stringcheck:"User name can only include Chinese characters, English letters, numbers, and underscores", minlength:"User name must be between 3-20 characters (2 characters in one text)" }, ///email: "Please enter your email address. ",password:{required: "Please enter your password", minlength: "Password must be at least 6 characters or more!" "} } });
Applicable version: Jquery-1.8.3.min.js, jquery-2.0.3.min.js
After validation in jquery validation, custom commits different action paths, suitable for a window that can either be added as a dialog box or as an Edit dialog box