jquery Validate.addmethod Regular Expressions (custom validation method)

Source: Internet
Author: User
Tags valid email address

Methods used by jquery to add a checksum in a project

$ (document). Ready (function () {
5
6/* setting Default Properties */
7$.validator.setdefaults ({
8 Submithandler:function (form) {
9 Form.submit ();
10}
11});
12
13//Character Verification
14jquery.validator.addmethod ("Stringcheck", function (value, Element) {
return this.optional (Element) | | /^[\u0391-\uffe5\w]+$/.test (value);
16}, "can only include Chinese characters, English letters, numbers and underscores";
17
18//two bytes in text
19jquery.validator.addmethod ("Byterangelength", function (value, element, param) {
var length = Value.length;
for (var i = 0; i < value.length; i++) {
if (Value.charcodeat (i) > 127) {
length++;
24}
25}
return this.optional (Element) | | (length >= param[0] && length <= param[1]);
27}, "Make sure the value entered is between 3-15 bytes (2 bytes in one of the characters)");
28
29//Identification Number Verification
30jquery.validator.addmethod ("Isidcardno", function (value, Element) {
return this.optional (Element) | | Isidcardno (value);
32}, "Please enter your ID number correctly");
33
34//Mobile phone Number verification
35jquery.validator.addmethod ("IsMobile", function (value, Element) {
The var length = value.length;
PNS var mobile =/^ ((13[0-9]{1}) | ( 15[0-9]{1})) +\d{8}) $/;
This.optional return (element) | | (length = = && Mobile.test (value));
39}, "Please fill in your mobile phone number correctly");
40
41//Phone Number Verification
42jquery.validator.addmethod ("Istel", function (value, Element) {
var tel =/^\d{3,4}-?\d{7,9}$/; Phone number format 010-12345678
This.optional return (element) | | (Tel.test (value));
45}, "Please fill in your phone number correctly");
46
47//Contact Number (Mobile/Phone) verification
48jquery.validator.addmethod ("Isphone", function (value,element) {
The 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));
53
54}, "Please fill in your contact number correctly");
55
56//Post Code verification
57jquery.validator.addmethod ("Iszipcode", function (value, Element) {
+ var tel =/^[0-9]{6}$/;
This.optional return (element) | | (Tel.test (value));
60}, "Please fill in your zip code correctly");
61
62//Start Validation
63$ (' #submitForm '). Validate ({
64/* Set validation rules */
Rules: {
Username: {
Required:true,
Stringcheck:true,
BYTERANGELENGTH:[3,15]
70},
email:{
Required:true,
Email:true
74},
phone:{
Required:true,
Isphone:true
78},
address:{
Required:true,
Bayi Stringcheck:true,
BYTERANGELENGTH:[3,100]
83}
84},
85
86/* Set error message */
Messages: {
Username: {
Required: "Please fill in the user name",
Stringcheck: "User name can only include Chinese characters, English letters, numbers and underscores",
Byterangelength: "User name must be between 3-15 characters (2 characters in one Chinese text)"
92},
email:{
94 Required: "Please enter an email address",
E-mail: "Please enter a valid email address"
96},
phone:{
98 Required: "Please enter your contact number",
Isphone: "Please enter a valid contact number"
100},
101 address:{
102 Required: "Please enter your contact address",
103 Stringcheck: "Please enter your contact address correctly",
104 Byterangelength: "Please detailed your contact address so that we could contact you"
105}
106},
107
108/* Set Validation trigger event */
109 Focusinvalid:false,
Onkeyup:false,
111
112/* Setting an error message to the DOM */
113 Errorplacement:function (Error, Element) {
Error.appendto (Element.parent ());
115},
116
117});
118
119});

Supplier-commons-vacation.js

Common function methods for defining orders
function Define_common_method () {

Set the default action
$.validator.setdefaults ({
Submithandler:function (form) {Form.submit ();}
});

Add a custom check function
$.validator.addmethod ("Charno", function (value,element) {
var length = Value.length;
var Your_tel =/[\w]/g;
return this.optional (Element) | | (Length<=8&&!your_tel.test (value));
}, "Please enter English characters or numbers!" ");

Add a check function to verify the name of the operation
$.validator.addmethod ("Charstring", function (value,element) {
var length = Value.length;
var Your_tel =/[^\a-za-z\u4e00-\u9fa5]/g;
var your_tel2=/^[a-za-z]*$/;
return this.optional (Element) | | (Length<=20&&!your_tel.test (value));
}, "Please enter the name in Chinese or English");

Verify your mobile phone number (starting with 13 and 15 only)
$.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 or mobile phone correctly");

}

Supplier-finance.js

JQuery (function ($) {

To bind all events
$ (document). Ready (function () {
Bind_component_event ();
});


Common events for a binding
function Bind_component_event () {
Define some common methods
Define_common_method ();

Verification of round-trip vendor payments (vacation)
Bind_checkcondition_component_event ();


Round-Trip Vendor payment verification (vendor)
Bind_supplierconditionform_component_event ();
}

Verification of round-trip vendor payment (vacation)
function Bind_checkcondition_component_event () {

Pending payment order Verification
$ ("#checkConditionForm"). Validate ({
Event: "Submit",
Errorplacement:function (Error, Element) {
},
rules:{
"Searchcon.accountno": {
Charno:true
},
"Searchcon.suppliername": {
Charstring:true
}
},
messages:{
"Searchcon.accountno": {
Charno: "Please enter the correct reconciliation number!" "
},
"Searchcon.suppliername": {
Charstring: "Please enter the correct supplier name!" "
}
},

Setting validation trigger Events
Focusinvalid:false,
Onkeyup:false,

Set error message hint DOM
Errorplacement:function (error,element) {
Error.appendto (Element.parent ());
}


});
}
Verification of round-trip vendor payments (vendor)
function Bind_supplierconditionform_component_event () {

Pending payment order Verification
$ ("#supplierConditionForm"). Validate ({
Event: "Submit",
Errorplacement:function (Error, Element) {
},
rules:{
"Searchcon.accountno": {
Charno:true
},
"Searchcon.suppliername": {
Charstring:true
}
},
messages:{
"Searchcon.accountno": {
Charno: "Please enter the correct reconciliation number!" "
},
"Searchcon.suppliername": {
Charstring: "Please enter the correct supplier name!" "
}
},

Setting validation trigger Events
Focusinvalid:false,
Onkeyup:false,

Set error message hint DOM
Errorplacement:function (error,element) {
Error.appendto (Element.parent ());
}
});
}

});

API about the checksum of jquery

Http://docs.jquery.com/Plugins/Validation/Validator/addMethod


Http://www.shopxx.net/html/news/2009/1201/59.html

Http://jquery.bassistance.de/api-browser/plugins.html

jquery Validate.addmethod Regular Expressions (custom validation method)

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.