Web front-end form validation

Source: Internet
Author: User

<FormId= "Registerform"Action=""Method= "POST"OnSubmit= "return Checkform ();">User name:<InputType= "Text"Id= "username"Name= "username"MaxLength= "20"Onblur= "Checkusername ()"/><SpanId= "Span1"></Span>Password:<InputType= "Password"Id= "Password"Name= "Password"MaxLength= "20"/> Confirm password: <input id= "Repassword"  Type= "password"  Name=" Repassword " Maxlength=" /> <input type=" submit " value = "register" ></form> 
functionCheckform () {//Verify User name://Get the value of the User Name text box:var username = document.getElementById ("username"). Value;if (username = =null | | Username = = "'{alert ("User name cannot be empty!"));ReturnFalse; }//Check Password://Get the value of the Password box:var password = document.getElementById ("Password"). Value;if (password = =null | | Password = = "'{Alert ("Password cannot be empty!"));ReturnFalse; }//Check Confirm password:var Repassword = document.getElementById ("Repassword"). Value;if (Repassword! =Password) {alert ("Two times password input is inconsistent!"));ReturnFalse; }}functionCheckusername () {//Get File Box value:var username = document.getElementById ("username"). Value;//1. Creating an asynchronous interaction objectvar xhr =Createxmlhttp ();//2. Set the monitoring Xhr.onreadystatechange =function(){if (xhr.readystate = = 4){if (Xhr.status = = 200) {document.getElementById ("Span1"). InnerHTML =Xhr.responsetext; }    }  }//3. Open the Connection Xhr.open ("GET", "${pagecontext.request.contextpath}/user_findbyname.action?time=" +New Date (). GetTime () + "&username=" +username,True);//4. Send Xhr.send (Null);}functionCreatexmlhttp () {VarXmlHttp;try{// Firefox, Opera 8.0+, Safari xmlhttp=new XMLHttpRequest (); }catch (e) { Try{// Internet Explorer xmlhttp=new    ActiveXObject ("msxml2.xmlhttp" catch (e) { Try{xmlhttp=new activexobject ("Microsoft.XMLHTTP" ); }catch (e) {}}} return< Span style= "COLOR: #000000" > xmlHttp;}            


Public String Findbyname ()ThrowsIOException {//Call service to query: User existuser =Userservice.findbyusername (User.getusername ());//Get Response object, item page output: httpservletresponse response =Servletactioncontext.getresponse ();  Response.setcontenttype ("Text/html;charset=utf-8");  determine if (existuser! = null) { // query to the user: the user name already exists response.getwriter (). println ("<font col  or= ' Red ' > username already exists </font> "); } Else { // did not query to the user: User name can use Response.getwriter (). println ("<font color= ' green ' > username can be used </  Font> "); } return NONE;}                
< Span style= "COLOR: #0000ff" > < Span style= "COLOR: #0000ff" > < Span style= "COLOR: #800000" > < Span style= "COLOR: #800000" >&NBSP;         

Web front-end form validation

Related Article

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.