jquery form Validation

Source: Internet
Author: User
Tags jquery form validation

Environment:

Jquery-1.10.1.min.js

Jquery.validate.min.js


tasks: form Validation


Html:

<form action= ""  id= "MyForm"  method= "POST" ><table class= ""  id= "table1" > <tbody>            <tr>               <td class= "" ></td>               <td><input  Type= "text"  id= "name"  name= "name"  value= ""  size= ""  class= "" ></td>               <td class= "Text_left"  style= "Color:red" ></td>             </tr>            <tr>               <td class= "" ></td>      &nbsP;        <td><input type= "Text"  id= "Tel"  name = "Tel"  value= " size=" " class=" "></td>               <td class= "Text_left"  style= "color:red" ></td>             </tr>             <tr>               <td class= "" ></td>               <td><input type= "text"  id= "addr"  name= "Addr"  value= " size=" " class=" "></td>               <td class= "Text_left"  style= "color:red" ></td>             </tr>             <tr>               <td class= "" ></td>               <td><input type= "text"  id= "Surplusnum"  name= "Surplusnum"  value= ""  size= " class=" "></td>               <td class= "Text_left"  style= "color:red" ></td>             </tr>         </tbody>    </table></form>


Jquery:

$ (function ()  {form.init ();}); /new validation rules.   Contact Phone (phone/Phone) verification. JQuery.validator.addMethod ("Istel", function  (value, element)  {  // (Area code)-(direct number)-(ext.) or 11-digit mobile phone number. Landline can have no extension number (area code)-(direct number).     var mobile = /^ ((0\d{2,3}) | ( 0\d{2,3}-)) \d{7,8} (-\d{1,4})?) $|^ (1[3584]\d{9}) $/;        if  (!mobile.exec (value))  return  false;    return true;},  "Please fill in the contact number of the parking point correctly");  //  can only enter a positive integer. JQuery.validator.addMethod ("Issurplusnum", function  (value, element)  {       var num = /^[1-9][0-9]{0,2}$/;         if  (!num.exec (value))  return false;    return true;},  " Please fill in the remaining number of vehicles correctly ");//  verify the form. Var form = function ()  {return {init : function ()  {$ ("#myform"). Validate ({rules : {name : {required : true,maxlength : 100},addr : {required :  true,maxlength : 200},tel : {required : true,isTel :  "#tel", minlength : 4,maxlength : 18},surplusnum : {required : true,min :  0,issurplusnum: "#surplusnum", max : 500}},messages : {name : {required  :  "Please enter name",maxlength :  "name must not exceed {0} characters",},addr : {required :  "Please enter Address", maxlength :  "Address must not exceed {0} characters",},tel : {required :  "Please enter the contact number",maxlength :  " Phone cannot exceed {0} characters ",istel : " phone number is malformed ",},surplusnum : {required : " Please enter the number of vehicles in the parking lot ", Max.  : jquery.format ("Number of vehicles not exceeding {0}"),}},errorplacement : function (error, element)  { if  (Element.parent (). is (' div '))  {error.appendto (Element.parent (). Parent (). Next ());  else {error.appendto (Element.parent (). Next ());}});}}; 


Help:

Regular expression:http://msdn.microsoft.com/zh-cn/library/ae5bf541 (vs.80). aspx

Validate Form validation:http://www.jb51.net/article/36067.htm


This article is from the "Night" blog, be sure to keep this source http://icyore.blog.51cto.com/8486958/1569740

jquery 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.