JQuery Validate Plugin Reomte usage

Source: Internet
Author: User

The most convenient way is to use the jquery Validate plugin Reomte method to determine whether or not the user account is registered by Ajax request when the user registers.

Jquery Validate plug-in, call remote method validation arguments, remote usage:

in the Validate method, addRemote: "Calibration Method", such as:Remote: "/test/checkaccount.jsp", then the parameter passed into the checkaccount.jsp is account=$ ("#account"). Val (), this is the Jquery.validate automatic parameter, without manual modification, if the parameter name is not a variable name, you can modify it by itself:

Remote: "/test/checkaccount.jsp?paramname=" + $ ("#account"). Val () the checksum method should return a Boolean value, for example: The account can be Out.print (false) or the account is not available out.print (true);

The registration code for the network is posted here:

$ ("#register"). Validate ({
Rules: {
"User.email": {
Required:true,
Email:true,
remote:{
Type: "POST",
URL: "/passport/account/validateemail",
data:{
Email:function () {return $ ("#email"). Val ();
}
}

}

                 //here omit the net   Part of the code for Sdg.registre.js

},
messages : {
" User.email ": {
required:" Please enter your email! ",
email:" Bad mailbox format! ",
Remote: "The mailbox has been registered!"
}
//omitted here net  sdg.registre.js part code
},
       //here omit good reach net  sdg.registre.js part code

});

corresponding HTML code  <input type=" text "class=" Input-block-level Tips "name=" User.email "id=" email > more HTML code for this page You can get yourself to the good up net go find it. net background is written with the jfinal framework, because did not see the backend code of the network, how to achieve the specific after the unclear.

The general method of checking in the background is:

Here is an example of SPRINGMVC, which lists the core code


@Controller
@RequestMapping ("/passport/account")

public class Useraction {

@Autowired

Usermanager usermanager;//User Management class, responsible for reading user data from the data

@RequestMapping (value =" /validateemail ", method = Requestmethod.post)

public String Validateemail ( HttpServletRequest request,httpservletresponse response) {

     String email= Request.getparamaters ("user.email ");

        Boolean isexisted=usermanager.isexisteduser (email); /from the database according to the EAMIL, whether the email is registered

       if (isexisted )

Response.Write ("true");

Else

        response.write (" false ");

return null;
}

}


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.