JQuery version of the text input box Inspector input Check_jquery

Source: Internet
Author: User
Tags datetime html tags
Copy Code code as follows:

/**
* Power by Wooshoo Copyright 2008-2009
* Program Name: JQuery Special Input Checker
* Content: specifically for input[text password hidden] and textarea user input to check
* The scope of the check includes: number of characters, whether it contains special characters, whether it is an integer, whether it conforms to the email format, whether it is a phone number,
* is the website address, is the picture address, is a floating-point decimal, is renminbi currency, is the date format
* is the time format, date time format, password format (contains only uppercase and lowercase letters, numbers, and underscores),
* Temporarily Unavailable: Whether it is a non-English special character format (that is, only Chinese, Japanese, Korean and other large character languages), whether to include HTML tags, whether to include UBB tags,
*
*/
(function ($) {
var WSHC = $.fn.check = function () {
Return Wshc.fn.init (this);
}
DATETIME = {
Full: ' Full ',
Simple: ' Simple ',
中文版: "中文版",
Japanese: "Japanese",
Chinese: "Chinese"
}
Wshc.fn = {
Init:function (obj) {
Wshc.fn.val = Obj.val ();
return WSHC.FN;
},
Notnull:function () {
if (this.val!== "" | | This.val!== undefined) {
return true;
}
Error ("You did not enter any characters.) ");
return false;
},
Number:function (Min,max) {//Check word number is over limit
if (this.val.length >= min && this.val.length <= max) {
return true;
}
Error ("You have entered a character that exceeds the" +min+ "-" +max+ "limit.) ");
return false;
},
Specialchar:function (PAT) {//check if special characters are included
Special characters include: \/@ # $% ^ & * = < > \ r
If you need to customize it, you can set it in parameters
Pat = Pat | | /[\\\/\@\#\$\%\^\&\*\=\<\>\n\r]+/;
Error ("The character you entered contains some special characters.") ");
Return Mat (This.val,pat);
},
Isnum:function (len) {//Check for numbers
if (!isnan (This.val)) {
return true;
}
Error ("You are not entering a number.) ");
return false;
},
Integer:function () {//Check for integer
if (This.val = = parseint (this.val)) {
return true;
}
Error ("You are not entering an integer.) ");
return false;
},
Float:function () {//Check for decimal
if (This.isnum () &&!this.integer ()) {
return true;
}
Error ("You are not entering a decimal number.) ");
return false;
},
Rmb:function () {//Check for currency (the RMB standard format is: 0.00 or 10.00 except Single-digit number first not 0)
var pat =/^ ([1-9][0-9]+|[ 0-9]) \. [0-9] {2}$/;
Error ("You are not entering renminbi currency format.) ");
Return Mat (This.val,pat);
},
Email:function (PAT) {//check that the e-mail format is compliant
Pat = Pat | | /^[a-za-z0-9_\-\.] +@[a-za-z0-9_\-\.] +\. [A-za-z] {0,4}$/;
Error ("You are not entering an e-mail format.) ");
Return Mat (This.val,pat);
},
Http:function (PAT) {//check if the address of the Web site (contains HTTP)
Pat = Pat | | /^ (http| HTTP): \/\/[^s]*/;
Error ("You are not entering a generic URL format.) ");
Return Mat (This.val,pat);
},
Url:function (PAT) {//Check whether it is a mailing address
Pat = Pat | | /^[a-za-z]+:\/\/[^s]*/;
Error ("You are not entering a generic communication protocol format.) ");
Return Mat (This.val,pat);
},
Image:function (PAT) {//Check for picture address (jpg gif png bmp jpeg)
Pat = Pat | | /^ (http| HTTP): \/\/[^s]* (jpg| Jpg|png| Png|gif| gif|bmp| Bmp|jpeg| JPEG) $/;
Error ("You are not entering a picture format that the page allows.) ");
Return Mat (This.val,pat);
},
Password:function (PAT) {
Pat = Pat | | /^\w*$/;
Error ("You are not entering a password format.) ");
Return Mat (This.val,pat);
},
Tel:function (PAT) {
Pat = Pat | | /^\d{3}\-\d{8}$|^\d{4}\-\d{7}$/;
Error ("You are not entering a fixed telephone format for the Chinese region.) ");
Return Mat (This.val,pat);
},
Mobile:function (PAT) {
Pat = Pat | | /^1\d{10}$/;
Error ("You have entered a mobile phone format that is not part of China.) ");
Return Mat (This.val,pat);
},
Datatime:function () {
return DATETIME;
},
Date:function (type) {
var Pat;
Switch (type) {
Case DATETIME. Full:
Pat =/^ ([1-9]\d{0,3}|0) \-\d{2}\-\d{2}) | (([1-9]\d{0,3}|0) \.\d{2}\.\d{2}) | (([1-9]\d{0,3}|0) \/\d{2}\/\d{2}) $/;
Break
Case DATETIME. Simple:
Pat =/^ (\d{2}\-\d{1,2}\-\d{1,2}) | (\d{2}\.\d{1,2}\.\d{1,2}) | (\d{2}\/\d{1,2}\/\d{1,2}) $/;
Break
Case DATETIME. 中文版:
Pat =/^\w* \d{1,2}, (([1-9]\d{0,3}|0) | ([1-9]\d{0,3}|0)] $/;
Break
Case DATETIME. Japanese:
Pat =/^ ([1-9]\d{0,3}|0) year \d{2} Month \d{2} day) $/;
Break
Case DATETIME. Chinese:
Pat =/^ ([1-9]\d{0,3}|0) year \d{2} Month \d{2} day) $/;
Break
}
Error ("The date you entered is not in the correct format. ");
Return Mat (This.val,pat);
},
Time:function (type) {
var Pat;
Switch (type) {
Case DATETIME. Full:
Pat =/^\d{2}:\d{2}:\d{2}$/;
Break
Case DATETIME. Simple:
Pat =/^\d{1,2}:\d{1,2}:\d{1,2}$/;
Break
Case DATETIME. 中文版:
Pat =/^\d{1,2}:\d{1,2}:\d{1,2}$/;
Break
Case DATETIME. Japanese:
Pat =/^\d{1,2} \d{1,2} \d{1,2} seconds $/;
Break
Case DATETIME. Chinese:
Pat =/^\d{1,2} \d{1,2} \d{1,2} seconds $/;
Break
}
Error ("The time you entered is not in the correct format.") ");
Return Mat (This.val,pat);
}
}
var mat = function (Val,pat) {
if (Val.match (PAT)) {
return true;
}
return false;
}
var error = function (err) {
Wshc.fn.error = Err | | "No format error. ";
}
}) (JQuery);
How to use:
The premise is that you have imported the jQuery3.2 package.
Js:
<scrpit>
$ (function () {
Check whether the word count exceeds the limit
$ (# "Do_check"). Bind ("click", Function () {
Alert ($ ("#wooshoo_ipt"). Check (). number ());
Alert ($ ("#wooshoo_ipt"). Check (). Error);
});
});
</script>
Html:
<body>
Please enter: <input id= "Wooshoo_ipt" type= "text"/><br/>
<a id= "Do_check" > Perform check </a>
</body>

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.