JQuery Validate Plugin Introduction
The JQuery Validate plugin provides a powerful validation feature for forms, making it easier to validate client forms, while providing a number of customization options to meet the needs of your application. The plugin bundles a set of useful validation methods, including URL and email validation, and provides an API to write user-defined methods. All bundled methods use English as an error message by default and are translated into 37 other languages.
The plugin was written and maintained by J?rn Zaefferer, a member of the jquery team, the main developer of the jquery UI team and the maintainer of qunit. The plugin began to appear in the early days of JQuery in 2006 and has been updated so far. The current version is 1.13.1 (ending: 2015.05.26).
Custom Phone Number Verification code
Mobile number verification JQuery.validator.addMethod ("IsMobile", function (value, Element) {var length = Value.length;var mobile =/^ (13[0 -9]{9}) | (18[0-9]{9}) | (14[0-9]{9}) | (17[0-9]{9}) | (15[0-9]{9}) $/;return this.optional (element) | | (length = = && Mobile.test (value));}, "Please fill in your mobile phone number correctly");
Validating forms
$ ("#checkPhoneForm"). Validate ({rules: {phone: {required:true,minlength:11,//) Custom method: Verify that the phone number exists in the database// Checkphoneexist:true,ismobile:true},code: {digits:true,required:true}},messages: {phone: {required: "Please enter phone number", M Inlength: "Confirm phone can not be less than 11 characters", IsMobile: "Please fill in your mobile phone number"},code: {required: "Please enter the code", digits: "Verification code should enter the number"}},errorplacement:f Unction (Error, Element) {Error.appendto (Element.next (). Next ());},ignore: ". Codecls"});
Html
<form id= "Checkphoneform" class= "Am-form" action= "${base?if_exists}/check-phone-succ.html" method= "POST" style= " width:100%; " ><label for= "Phone" style= "display:block;" > Mobile number:</label> <input type= "text" id= "phone" name= "phone" value= "" maxlength= "one" style= "width:220px; Display:inline-block; margin-right:20px; " ><!--Send Verification code button--><input type= "button" id= "btn" value= "Free Verification Code" onclick= "Time (this);"/><span class= " ErrorMsg "style=" width:200px; Text-align:left; Display:inline-block; " ></span><br> <label for= "code" > Verification Code:</label><!--input Verification code-<input type= "text" name = "Code" id= "code" value= "" maxlength= "4" style= "width:220px;" > <span style= "width:0px; Text-align:left; Display:inline-block; " ></span><!--Store error message--><span id= "Codespanid" class= "errormsg" style= "width:200px; Text-align:left; Display:inline-block; " ></span><br><div class= "AM-CF" ><input type= "submit" ID= "Subbtn" class= "am-btn am-btn-primary am-btn-sm am-fl" value= "Next" ></div></form>
Jquery Validation Plugin Verification phone number