Php--validate Form Validation

Source: Internet
Author: User

Validate Form Validation extension rules

Add a custom test

Addmethod:name, method, message     

Extended Validation rules

Mailbox Form Validation rules
JQuery.validator.addMethod ("Mail", function (value, Element) {
var mail =/^[a-z0-9._%-][email protected] ([a-z0-9-]+\.) +[a-z]{2,4}$/;
return this.optional (Element) | | (Mail.test (value));
}, "The mailbox format is not correct");

Phone verification Rules
JQuery.validator.addMethod ("Phone", function (value, Element) {
var phone =/^0\d{2,3}-\d{7,8}$/;
return this.optional (Element) | | (Phone.test (value));
}, "Phone format: 0371-68787027");

Area code validation rules
JQuery.validator.addMethod ("AC", function (value, Element) {
var ac =/^0\d{2,3}$/;
return this.optional (Element) | | (Ac.test (value));
}, "area code such as: 010 or 0371");

No area code phone verification rules
JQuery.validator.addMethod ("Noactel", function (value, Element) {
var noactel =/^\d{7,8}$/;
return this.optional (Element) | | (Noactel.test (value));
}, "Phone format: 68787027");

Mobile Verification Rules
JQuery.validator.addMethod ("mobile", function (value, Element) {
var mobile =/^1[3|4|5|7|8]\d{9}$/;
return this.optional (Element) | | (Mobile.test (value));
}, "Phone format is incorrect");

Email or mobile verification rules
JQuery.validator.addMethod ("MM", function (value, Element) {
var mm =/^[a-z0-9._%-][email protected] ([a-z0-9-]+\.) +[a-z]{2,4}$|^1[3|4|5|7|8]\d{9}$/;
return this.optional (Element) | | (Mm.test (value));
}, "not formatted");

Phone or phone verification rules
JQuery.validator.addMethod ("TM", function (value, Element) {
var tm=/(^1[3|4|5|7|8]\d{9}$) | (^\d{3,4}-\d{7,8}$) | (^\d{7,8}$) | (^\d{3,4}-\d{7,8}-\d{1,4}$) | (^\d{7,8}-\d{1,4}$)/;
return this.optional (Element) | | (Tm.test (value));
}, "not formatted");

Age form Validation rules
JQuery.validator.addMethod ("Age", function (value, Element) {
var age =/^ (?: [1-9][0-9]?| 1[01][0-9]|120) $/;
return this.optional (Element) | | (Age.test (value));
}, "cannot exceed 120 years old");
20-60/^ ([2-5]\d) |60$/

Fax
JQuery.validator.addMethod ("Fax", function (value,element) {
var fax =/^ (\d{3,4})? [-]?\d{7,8}$/;
return this.optional (Element) | | (Fax.test (value));
}, "Fax format: 0371-68787027");

Verify that the values of the current and destination Val are equal and return to False
JQuery.validator.addMethod ("EqualTo2", function (value, Element) {
var returnval = true;
var id = $ (Element). attr ("Data-rule-equalto2");
var Targetval = $ (ID). val ();
if (value = = = Targetval) {
ReturnVal = false;
}
return returnval;
}, "cannot be the same as the original password");

is greater than the specified number
JQuery.validator.addMethod ("GT", function (value, Element) {
var returnval = false;
var GT = $ (Element). Data ("GT");
if (Value > GT && Value! = "") {
ReturnVal = true;
}
return returnval;
}, "cannot be less than 0 or empty");

Chinese characters
JQuery.validator.addMethod ("Chinese", function (value, Element) {
var Chinese =/^[\u4e00-\u9fff]+$/;
return this.optional (Element) | | (Chinese.test (value));
}, "not formatted");

Integer multiple of the specified number
JQuery.validator.addMethod ("Times", function (value, Element) {
var returnval = true;
var base=$ (Element). attr (' data-rule-times ');
if (value%base!=0) {
Returnval=false;
}
return returnval;
}, "must be an integral multiple of the release Bounty");

Id
JQuery.validator.addMethod ("Idcard", function (value, Element) {
var isidcard1=/^[1-9]\d{7} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{3}$/;//(15-bit)
var isidcard2=/^[1-9]\d{5}[1-9]\d{3} ((0\d) | ( 1[0-2]) (([0|1|2]\d) |3[0-1]) \d{3} ([0-9]| X) $/;//(18-bit)

return this.optional (Element) | | (Isidcard1.test (value)) | | (Isidcard2.test (value));
}, "not formatted");


Character verification
JQuery.validator.addMethod ("Stringcheck", function (value, Element) {
return this.optional (Element) | | /^[\u0391-\uffe5\w]+$/.test (value);
}, "can only include Chinese characters, English letters, numbers and underscores";
------------------------------------------------------------
Chinese characters two bytes
JQuery.validator.addMethod ("Byterangelength", function (value, element, param) {
var length = Value.length;
for (var i = 0; I <</span> value.length; i++) {
if (Value.charcodeat (i) > 127) {
length++;
}
}
return this.optional (Element) | | (length >= param[0] && length <= param[1]);
}, "Make sure the value entered is between 3-15 bytes (2 bytes in one text)");
------------------------------------------------------------
Identification Number Verification
JQuery.validator.addMethod ("Isidcardno", function (value, Element) {
return this.optional (Element) | | Isidcardno (value);
}, "Please enter your ID number correctly");
------------------------------------------------------------
Mobile phone number Verification
JQuery.validator.addMethod ("IsMobile", function (value, Element) {
var length = Value.length;
var mobile =/^[1][3-8]+\\d{9}/;
return this.optional (Element) | | (length = = && Mobile.test (value));
}, "Please fill in your mobile phone number correctly");
------------------------------------------------------------
Phone number Verification
JQuery.validator.addMethod ("Istel", function (value, Element) {
var tel =/^\d{3,4}-?\d{7,9}$/; Phone number format 010-12345678
return this.optional (Element) | | (Tel.test (value));
}, "Please fill in your phone number correctly");
------------------------------------------------------------
Contact Phone (phone/Phone) verification
JQuery.validator.addMethod ("Isphone", function (value,element) {
var length = Value.length;
var mobile =/^ ((13[0-9]{1}) | ( 15[0-9]{1})) +\d{8}) $/;
var tel =/^\d{3,4}-?\d{7,9}$/;
return this.optional (Element) | | (tel.test (value) | | mobile.test (value));

}, "Please fill in your contact number correctly");
------------------------------------------------------------
ZIP Code Verification
JQuery.validator.addMethod ("Iszipcode", function (value, Element) {

var tel =/^[0-9]{6}$/;
return this.optional (Element) | | (Tel.test (value));
}, "Please fill in your zip code correctly");

Php--validate 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.