JQuery Validate plug-in Authentication user registration information _jquery

Source: Internet
Author: User
Tags rand

Using jquery's validate plug-in to do client-side validation is handy, and here's an example of using the Validate plug-in to authenticate user registration information.

This example uses the 1.5 version .

The example is done under SSH with the following code:

registe.jsp

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  

Main methods of background Registeaction.java

Public String Execute () throws Exception {Map session = Actioncontext.getcontext (). GetSession (); 
 String ver2 = (string) session.get ("Rand"); 
 Session.put ("Rand", NULL); Determine if the validation code is correct if (vercode.equals (ver2)) {if (Usermanager.validname (username)) {if Usermanager.adduser (username, pas 
 Sword, email) > 0) return SUCCESS; else Addactionerror ("registration failed, please try again!") 
 "); } else {Addactionerror ("This username already exists, please re-enter!") 
 "); 
 } else {addactionerror ("Verify code mismatch, please re-enter"); 
 
} return INPUT; 
 //Verify that the user name is available with public String validname () throws Exception {System.out.println (username); 
 Boolean flag = Usermanager.validname (username); 
 HttpServletResponse response = Servletactioncontext.getresponse (); 
 Response.setdateheader ("Expires", 0); 
 Response.AddHeader ("Pragma", "No-cache"); 
 Response.setheader ("Cache-control", "No-cache"); 
 Response.setcontenttype ("Text/plain;charset=utf-8"); 
 if (flag) Response.getwriter (). Write ("true"); 
 else Response.getwriter (). Write ("false"); REsponse.getwriter (). Flush (); 
 Returns null because the content is output directly without passing through a JSP. 
return null; 


 }

The effect chart is as follows:

Note: the method of using remote asynchronously to authenticate the username should be output by Response.getwriter (). Write ("true"), rather than returning the string as normal.

For more detailed information on plug-ins you can view the "jQuery Validate Verification Plug-in usage details."

In addition, jquery also supports the dynamic addition of checksums to controls, such as:

Copy Code code as follows:
("#email"). Rules ("Add", {required:true, email:true});

Note, however, that if you dynamically add checksums to the elements in a collection, you need to iterate over each element because jquery implicitly implements the collection operation, but the validate plugin does not. For example:

$ (". Quantity"). each (function () { 
 $ (this). Rules ("Add", {digits:true,required:true}); 
}; 

The above is the entire content of this article, I hope to help you learn.

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.