The
code is as follows:
<form action= "" method= "Post" id= "Formvalidate" > value: <input name= "" type= "text" validate= "number"/>& lt;span></span><br/> floating-point type: <input name= "" type= "text" validate= "decimal"/><span> </span><br/> English: <input name= "" type= "text" validate= "中文版"/><span></span> <br/> Capital English: <input name= "" type= "text" validate= "Upper_english"/><span></span><br/ > lowercase English: <input name= "" type= "text" validate= "Lower_english"/><span></span><br/> Message format: <input name= "" type= "text" validate= "email"/><span></span><br/> whether to include Chinese: <input name= "" type= "text" validate= "Chinese"/><span></span><br/> Url:<input, Name= "" Type= "text" validate= "url"/><span></span><br/> phone number: <input name= "" type= "text" validate= "Phone"/><span></span><br/> IP address: <input name= ""Type=" text "validate=" IP/><span></span><br/> Amount: <input name= "" type= "text" Validate = "Money"/><span></span><br/> numeric value or English or _:<input name= "type=" text "validate=" Number_ Letter "/><span></span><br/> ZIP code: <input name=" "type=" text "validate=" Zip_Code "/> <span></span><br/> available accounts: <input name= "" type= "text" validate= "account"/><span> </span><br/> qq:<input name= "" type= "text" validate= "QQ"/><span></span><br/ > ID: <input name= "" type= "text" validate= "card"/><span></span><br/> values are allowed to be null: <input name= "" type= "text" validate= "number" empty= ' yes '/><span></span><br/> numeric length 1-3: <input name= "" type= "text" validate= "number" min=1 max=3 value length 1-3 Allow null: <input name= "" type= "text" validate= "number" Min=1 max=3' Yes '/><span></span><br/> <input name= ' type= ' Submit '/> </form> <script src= "jquery.js" type= "Text/javascript" ></script> <script src= "Formvalidate.js" Type= "Text/javascript" ></script> <script type= "Text/javascript" > var formvalidate = new Formvalidate (); formvalidate.init ({}); </script> [javascript] code is as follows:/* * General JS Verification Class * Use Method: * var formvalidate = new Formvalidate (); * Formvalidate.init ({}); * Note: * &L T;form action= "" method= "Post" id= "Formvalidate" > * ID is formvalidate * * <input name= "" Type= " Text "validate=" Zip_Code "empty=" yes "min=10 max=10/><span></span> * validate=" Zip_Code " Verify that the ZIP code * empty= "yes" verifies that nulls are allowed * min=10 Minimum length * max=10 Maximum length * <span></span> display prompt content &nb Sp */ var formvalidate = function () { var _this = this; This.options = { Number: {reg:/^[0-9]+$/, str: ' must be numeric '}, decimal: {reg:/^[-]{0,1} (d+) [.] + (d+) $/, str: ' must be in decimal format '}, Chinese: {reg:/^[a-za-z]+$/, str: ' must be English letter '}, upper_english: {reg:/^[a -z]+$/, str: ' must be uppercase English letter '}, lower_english: {reg:/^[a-z]+$/, str: ' must be lowercase English letter '}, Email: {reg:/^ ([a-za-z0- 9]+[_|_|.] *[a-za-z0-9]+@ ([a-za-z0-9]+[_|_|.]?) *[a-za-z0-9]+. [A-za-z] {2,3}$/, str: ' Email format incorrect '}, Chinese: {reg:/[u4e00-u9fa5uf900-ufa2d]/ig, str: ' must contain Chinese '}, URL: {reg:/^[ a-za-z]+://[^s]*/, str: ' URL format not correct '}, phone: {reg:/^[1][3][0-9]{9}$/, str: ' Phone number format is incorrect '}, IP: {reg:/^ (d +). (d+). (d+). (d+) $/, str: ' Incorrect IP address format '}, : {reg:/^[0-9]+[.] [0-9] {0,3}$/, str: ' The amount format is incorrect '}, number_letter: {reg:/^[0-9a-za-z_]+$/, str: ' Only allow input in English letters, numbers, _ '}, Zip_Code: {RE G:/^[a-za-z0-9]{3,12}$/, str: ' ZIP code incorrectly formatted '}, account: {reg:/^[a-za-z][a-za-z0-9_]{4,15}$/, str: ' Username notLegal, allow 5-16 characters, letters underline and number '}, QQ: {reg:/[1-9][0-9]{4,}/, str: ' QQ account incorrect '}, card: {reg:/^ (d{6}) (18|19|20)? ( D{2}) ([01]d) ([0123]d) (D{3}) (d| X)? $/, str: ' ID number incorrect '}, }; //initialization binding form options This.init = function (options) { this.setoption s (options); this.checkform (); }; //setting parameters This.setoptions = function (options) { for ( var key in Options) { if (key in this.options) { This.options[key] = options[key]; } } };&nb Sp //Detection form includes NULL, maximum minimum value, regular validation this.checkform = function () { $ ("#formValidate"). Submit (function () {  ; var Formchind = $ ("#formValidate"). Children (); var testresult = true; Formchind.each (function (i) { var Child = Formchind.eq (i); var value = Child.val (); var len = value.length; var childspan = Child.next (); //property is empty case if (child.attr (' empty ')) { if (child.attr (' empty ') = = ' Yes ' && value= = ') { if (Childspan) { childspan.html ('); } -return; } //Properties Min and Ma X Max and min length var min = null; var max = null; if (child.attr (' min ')) min = child.attr (' min '); if (chil D.attr (' Max ') max = child.attr (' Max '); if (min && max) { if (len < min | | len > Max) { if (Childspan) { childspan.html ('); childspan.html (' string length between ' + min + ' and ' + Max + '); TestResult = false; Retu rn; } } } else if (min) { if (len < min) { if (Childspan) { childspan.html ('); &nbs P childspan.html (' string length should be greater than ' + min '); testresult = false; return; } } } else if (max) { I F (Len > Max) { if (Childspan) { childspan.html ('); childspan.html (' string length should be less than ' + Max '); testres Ult = false; return; } } } //Regular checksum if (child.attr (' Validate ')) { var type = Child.attr (' Validate '); var result = _this.check (value, type); if (Childspan) { childspan.html ('); if (Result!= true) { childspan.html (' + result); TestResult = false; } -} } }); return test result; }); }; //Detect a single regular option This.check = function (value, type) { if (this.options[type ]) { var val = this.options[type][' reg ']; if (!val.test (value)) { return this.options[type][' str '];& nbsp } return true; } else { "I can't find this form to validate the regular item '; } }; }