Jquery data verification plug-in (self-made, simple, hands-on) instance code _ jquery

Source: Internet
Author: User
Recently, many JavaScript data verifications were performed in the project. to unify the style and port reuse, Jquery plug-ins were encapsulated. The Code is as follows:


(Function ($ ){
Var defaults = {
BugColor: '# ffcccc', // text box color when data is incorrect
Color: 'white', // the text box color when the data is correct
Type: "alert", // when a data error occurs, the prompt mode alert dialog box is displayed. The text value is span html.
Msg: "Msg", // content prompt when data is incorrect
ResOjId: 'no' // tag assigned when the test method is used # id
};
Function UiProcess (options, rexString, object ){
Var options = $. extend (defaults, options );
Var values = object. val ();
If (rexString. test (values )){
Object.css ("backgroundColor", options. color );
Return true;
} Else {
Object.css ("backgroundColor", options. bugColor );
If (options. type = "alert "){
Alert (options. msg );
}
If (options. type = "text "){
Optional (options.resojid).html (options. msg );
}
Return false;
}
}
// Verify that the ip address meets the format
$. Fn. RegIp = function (options ){
Var rexString =/^ \ d {1} \. {1} \ d {1} \. {1} \ d {1 }/;
Return UiProcess (options, rexString, this)
}
// Verify whether the landline is in the correct format
$. Fn. RegTelPhone = function (options ){
Var rexString =/^ [0-9] + [-]? [0-9] + [-]? [0-9] $ /;
Return UiProcess (options, rexString, this)

}
// Verify that the mobile phone is in the correct format
$. Fn. RegMombilePhone = function (options ){
Var rexString =/(^ 189 \ d {8} $) | (^ 13 \ d {9} $) | (^ 15 \ d {9} $ )/;
Return UiProcess (options, rexString, this)

}
// Verify that Chinese characters are in the correct format
$. Fn. RegCHZN = function (options ){
Var rexString =/[\ u4e00-\ u9fa5]/;
Return UiProcess (options, rexString, this)

}
// Verify that decimal complies with the format
$. Fn. RegDecimal = function (options ){
Var rexString =/^ [0-9] + [.]? [0-9] + $ /;
Return UiProcess (options, rexString, this)

}
// Verify whether decimal retains one decimal in the correct format
$. Fn. RegDecimalSign = function (options ){
Var rexString =/^ [+-]? [0-9] + [.]? [0-9] + $ /;
Return UiProcess (options, rexString, this)

}
// Verify whether the integer retains one decimal point in the format
$. Fn. RegNumber = function (options ){
Var rexString =/^ [0-9] + $ /;
Return UiProcess (options, rexString, this)

}
// Verify that each integer retains one decimal point in the correct format
$. Fn. RegNumberSign = function (options ){
Var rexString =/^ [+-]? [0-9] + $ /;
Return UiProcess (options, rexString, this)

}
// Verify non-null characters
$. Fn. IsEmpty = function (options ){
Var rexString =/(^. + $) | ([\ u4e00-\ u9fa5])/;
Return UiProcess (options, rexString, this)

}
}) (JQuery );

Call:

The Code is as follows:


Related Article

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.