Mobile phone number verified by Jquery Validation plug-in
JQuery Validate plug-in Introduction
The jQuery Validate plug-in provides powerful form verification functions to simplify form verification on the client side. It also provides a large number of custom options to meet various application needs. This plug-in is bundled with a set of useful verification methods, including URL and email verification, and provides an API for Writing user-defined methods. All bundling methods use English as the error message by default and have been translated into 37 other languages.
This plug-in is composed of J? Rn Zaefferer was written and maintained. He is a member of the jQuery team, a major developer of the jQuery UI team, and a QUnit maintainer. This plug-in started to appear in early jQuery in 2006 and has been updated to date. The current version is 1.13.1 (as of: 2015.05.26 ).
Custom mobile phone number verification code
// Verify the jQuery mobile phone number. 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 = 11 & mobile. test (value) ;}, "Please enter your mobile phone number correctly ");
Verification Form
$ ("# CheckPhoneForm "). validate ({rules: {phone: {required: true, minlength: 11, // custom method: Check whether the mobile phone number exists in the Database // checkPhoneExist: true, isMobile: true}, code: {digits: true, required: true }}, messages: {phone: {required: "Enter your mobile phone number", minlength: "Make sure that the mobile phone number cannot be less than 11 characters", isMobile: "Please enter your mobile phone number correctly"}, code: {required: "Please enter the verification code", digits: "Verification Code should enter a number" }}, errorPlacement: function (error, element) {error. appendTo (element. next (). next () ;}, ignore :". codeCls "});
HTML