How to use jquery for simple form validation

Source: Internet
Author: User

How to use jquery for simple form validation:
jquery can be used to form validation, of course, there are more complex forms validation, here is not introduced, the following is a brief introduction of how to use jquery simple form verification, and then we can be modified to perform basic expression verification. Let's look at a code example:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.51texiao.cn/" /><title>Ant Tribe</title><styletype= "Text/css">Body{font-size:11px}#divLogin{margin:15% 0 0 15%}#divLogin fieldset{width:300px;padding:0px;margin:0px}#divLogin fieldset h3{margin:0px;padding:5px;Background-color:#eee}#divLogin fieldset. Content{padding:20px;Line-height:2.6em}#divLogin fieldset. Content. Btncenter{text-align:Center}. txt{Border:#666 1px solid;padding:2px;width:180px;Margin-right:3px}. BTN{Border:#666 1px solid;padding:2px;width:60px;Filter:progid:DXImageTransform.Microsoft.Gradient (gradienttype=0, startcolorstr= #ffffff, endcolorstr= #ECE9D8)}</style><Scripttype= "Text/javascript"src= "Mytest/jquery/jquery-1.8.3.js"></Script><Scripttype= "Text/javascript">$ (document). Ready (function(){      $("#Button1"). Click (function() { //button click event         var$name= $("#txtName"); //User name         var$pass= $("#txtPass"); //Password         if($name. Val ()== "") {alert ("the user name cannot be empty!");            $name. focus (); return false; }          Else{alert ("The password cannot be empty!");            $pass. focus (); return false; }      })   })</Script></Head><Body><DivID= "Divlogin">  <fieldset>    <H3>User Login</H3>    <Divclass= "Content">      <Div>User:<inputID= "Txtname"type= "text"class= "txt" />      </Div>      <Div>Password:<inputID= "Txtpass"type= "Password"class= "txt"/>      </Div>      <Divclass= "Btncenter">        <inputID= "Button1"type= "button"value= "Login"class= "BTN" />        <inputID= "Reset1"type= "Reset"value= "Cancel"class= "BTN" />      </Div>    </Div>  </fieldset></Div></Body></HTML>

The above code implements the basic form verification function, of course, can continue to complicate, but also can make the page more beautiful, will be introduced slowly.

The original address is: http://www.51texiao.cn/jqueryjiaocheng/2015/0504/669.html

How to use jquery for simple form validation

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.