JQuery text input box checker InputCheck_jquery

Source: Internet
Author: User
Checks user input of input [textpasswordhidden] And textarea. The Code is as follows:


/**
* Power by wooshoo copyright 2008-2009
* Program name: JQuery dedicated input checker
* Content: Checks user input of input [text password hidden] And textarea.
* The check scope includes: number of characters, whether it contains special characters, whether it is an integer, whether it complies with the email format, whether it is a telephone number,
* Is it a website address, an image address, a floating point decimal number, a Renminbi currency, or a date format?
* Whether it is a time format, whether it is a date and time format, whether it is a password format (only including uppercase and lowercase letters, numbers, and dashes ),
* Unavailable for the moment: whether it is a non-English special character format (that is, it is only for Chinese, Japanese, Korean and other major character languages), whether it contains html tags, whether it contains UBB tags,
*
*/
(Function ($ ){
Var wshc = $. fn. check = function (){
Return wshc. fn. init (this );
}
DATETIME = {
FULL: "full ",
SIMPLE: "simple ",
ENGLISH: "english ",
Japan: "Japan ",
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 have not entered any characters. ");
Return false;
},
Number: function (min, max) {// check whether the number of words exceeds the limit
If (this. val. length> = min & this. val. length <= max ){
Return true;
}
Error ("the character you entered exceeds the limit of" + min + "-" + max +. ");
Return false;
},
SpecialChar: function (pat) {// check whether it contains special characters
// Special characters include: // @ # $ % ^ & * = <> \ n \ r
// If You Need to customize it, you can set it in the Parameter
Pat = pat |/[\\\/\@\#\$ \%\^\\\\ * \=\<\> \ n \ r] + /;
Error ("the character you entered contains some special characters. ");
Return mat (this. val, pat );
},
IsNum: function (len) {// check whether it is a number
If (! IsNaN (this. val )){
Return true;
}
Error ("You are not entering a number. ");
Return false;
},
Integer: function () {// check whether it is an integer
If (this. val = parseInt (this. val )){
Return true;
}
Error ("You are not entering an integer. ");
Return false;
},
Float: function () {// check whether it is a decimal number
If (this. isNum ()&&! This. integer ()){
Return true;
}
Error ("You entered not decimals. ");
Return false;
},
RMB: function () {// check whether it is a currency (RMB Standard Format: 0.00 or 10.00, except the single digit, the first digit is not zero)
Var pat =/^ ([1-9] [0-9] + | [0-9]) \. [0-9] {2} $ /;
Error ("your input is not in the renminbi format. ");
Return mat (this. val, pat );
},
Email: function (pat) {// check whether the email format is correct
Pat = pat |/^ [a-zA-Z0-9 _ \-\.] + @ [a-zA-Z0-9 _ \-\.] + \. [a-zA-Z] {0, 4} $ /;
Error ("the email format you entered is not. ");
Return mat (this. val, pat );
},
Http: function (pat) {// check whether it is the website address (including http)
Pat = pat |/^ (http | HTTP): \/[^ s] */;
Error ("the URL you entered is not in the common URL format. ");
Return mat (this. val, pat );
},
Url: function (pat) {// check whether it is a communication address
Pat = pat |/^ [a-zA-z] +: \/[^ s] */;
Error ("the format you entered is not a universal communication protocol. ");
Return mat (this. val, pat );
},
Image: function (pat) {// check whether it is an image address (jpg gif png bmp jpeg)
Pat = pat |/^ (http | HTTP ): \ // \/[^ s] * (jpg | JPG | png | PNG | gif | GIF | bmp | BMP | jpeg | JPEG) $ /;
Error ("the image format you entered is not allowed on the webpage. ");
Return mat (this. val, pat );
},
Password: function (pat ){
Pat = pat |/^ \ w * $ /;
Error ("the password format you entered is not. ");
Return mat (this. val, pat );
},
Tel: function (pat ){
Pat = pat |/^ \ d {3} \-\ d {8 }$ | ^ \ d {4} \-\ d {7} $ /;
Error ("the phone format you entered is not in China. ");
Return mat (this. val, pat );
},
Mobile: function (pat ){
Pat = pat |/^ 1 \ d {10} $ /;
Error ("the mobile phone format you entered is not in 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} \-\ d {1}) | (\ d {2 }\. \ d {1, 2 }\. \ d {1, 2}) | (\ d {2} \/\ d {1, 2} \/\ d {1, 2}) $ /;
Break;
Case DATETIME. ENGLISH:
Pat =/^ \ w * \ d {1, 2}, ([1-9] \ d {0, 3} | 0) | ([1-9] \ d {0, 3} | 0) $ /;
Break;
Case DATETIME. Japan:
Pat =/^ ([1-9] \ d {0, 3} | 0)-d {2}-d {2}) $ /;
Break;
Case DATETIME. CHINESE:
Pat =/^ ([1-9] \ d {0, 3} | 0)-d {2}-d {2}) $ /;
Break;
}
Error ("the date format you entered is incorrect. ");
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. ENGLISH:
Pat =/^ \ d {1, 2 }:\ d {1, 2 }:\ d {1, 2} $ /;
Break;
Case DATETIME. Japan:
Pat =/^ \ d {1, 2} hour d {1, 2} minute d {1, 2} seconds $ /;
Break;
Case DATETIME. CHINESE:
Pat =/^ \ d {1, 2} hour d {1, 2} minute d {1, 2} seconds $ /;
Break;
}
Error ("the time format you entered is incorrect. ");
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 );
Usage:
The premise is that you have imported the jQuery3.2 package
JS:

$ (Function (){
// Check whether the number of words exceeds the limit
$ (# "Do_check"). bind ("click", function (){
Alert ($ ("# wooshoo_ept"). check (). number ());
Alert ($ ("# wooshoo_ept"). check (). error );
});
});
Script
HTML:

Enter:

Run check

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.