jquery Data Validation plug-in (self-made, simple, practicing) instance code _jquery

Source: Internet
Author: User

Copy Code code as follows:

(function ($) {
var defaults = {
Bugcolor: ' #FFCCCC ',//When the data is wrong, text box color
Color: ' white ',//Data Right time text box colors
Type: "Alert",///When the data is wrong prompt way alert pop-up box text assignment span HTML
msg: "MSG",///When the data is wrong, prompt content
Resojid: ' No '//when the test method is assigned to the label #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") {
$ (options.) Resojid). HTML (OPTIONS.MSG);
}
return false;
}
}
Verify that the IP conforms to the format
$.fn. REGIP = function (options) {
var rexstring =/^\d{1,3}\. {1}\d{1,3}\. {1}\d{1,3}/;
Return uiprocess (Options, rexstring, this)
}
Verify that the landline is in line with the format
$.fn. Regtelphone = function (options) {
var rexstring =/^[0-9]+[-]? [0-9]+[-]? [0-9]$/;
Return uiprocess (Options, rexstring, this)

}
Verify that the phone matches the format
$.fn. Regmombilephone = function (options) {
var rexstring =/(^189\d{8}$) | (^13\d{9}$) | (^15\d{9}$)/;
Return uiprocess (Options, rexstring, this)

}
Verify Chinese is in line with format
$.fn. REGCHZN = function (options) {
var rexstring =/[\u4e00-\u9fa5]/;
Return uiprocess (Options, rexstring, this)

}
Verify that decimal matches the format
$.fn. Regdecimal = function (options) {
var rexstring =/^[0-9]+[.]? [0-9]+$/;
Return uiprocess (Options, rexstring, this)

}
Verify that decimal keeps a decimal number in the format
$.fn. Regdecimalsign = function (options) {
var rexstring =/^[+-]? [0-9]+[.]? [0-9]+$/;
Return uiprocess (Options, rexstring, this)

}
Verify that the integer retains a decimal number in the format
$.fn. Regnumber = function (options) {
var rexstring =/^[0-9]+$/;
Return uiprocess (Options, rexstring, this)

}
Verify that the integers keep a decimal number in the format
$.fn. Regnumbersign = function (options) {
var rexstring =/^[+-]? [0-9]+$/;
Return uiprocess (Options, rexstring, this)

}
Verifying non-null characters
$.fn. IsEmpty = function (options) {
var rexstring =/(^.+$) | ([\U4E00-\U9FA5])/;
Return uiprocess (Options, rexstring, this)

}
}) (JQuery);

Call:

Copy Code code as follows:

<script type= "Text/javascript" >
function Submitok () {
var interfacenameinput = $ ("#<%=interfacename.clientid%>");
var usernameinput = $ ("#<%=username.clientid%>");
var passwordinput = $ ("#<%=password.clientid%>");
var interfaceurlinput = $ ("#<%=interfaceurl.clientid%>");;
If!interfacenameinput.isempty ({"MSG": "Interface name is malformed!) "})" {return false}
If!usernameinput.isempty ({"MSG": "Malformed!) "})" {return false}
If!passwordinput.isempty ({"MSG": "Malformed!) "})" {return false}
If!interfaceurlinput.isempty ({"MSG": "Malformed!) "})" {return false}
}
</script>

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.