Js determines whether the input is Chinese, numbers, ID cards, and so on. Page 1/3 of the js function set

Source: Internet
Author: User

*
Determines whether the specified content is null. If it is null, a warning box is displayed.
*/
Function isEmpty (theValue, strMsg ){
If (theValue = ""){
Alert (strMsg + "cannot be blank! ");
Return true;
}
Return false;
}
/*
Chinese judgment function, which allows the replacement of uncommon words with English "*"
True indicates that the condition is met, and false indicates that the condition is not met.
*/
Function isChinese (str ){
Var badChar = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
BadChar + = "abcdefghijklmnopqrstuvwxyz ";
BadChar + = "0123456789 ";
BadChar + = "" + ""; // halfwidth and fullwidth Spaces
BadChar + = "'~! @ # $ % ^ & ()-_ = +] \\| :;\" \\' <,>? /"; // It does not contain the English characters * or.
If ("" = str ){
Return false;
}
For (var I = 0; I var c = str. charAt (I); // character in string str
If (badChar. indexOf (c)>-1 ){
Return false;
}
}
Return true;
}
/*
Number judgment function. If true is returned, all digits are returned. If false is returned, not all digits are returned.
*/
Function isNumber (str ){
If ("" = str ){
Return false;
}
Var reg =/\ D /;
Return str. match (reg) = null;
}
/*
Determines whether the given string is a number of the specified length.
True is returned, not false.
*/
Function isNumber_Ex (str, len ){
If ("" = str ){
Return false;
}

If (str. length! = Len ){
Return false;
}

If (! IsNumber (str )){
Return false;
}
Return true;
}

/*
The money judgment function allows the first digit to be "-" to indicate that the account is in arrears.
True indicates that the format is correct. false indicates that the format is incorrect.
*/
Function isMoney (str ){
If ("" = str ){
Return false;
}
For (var I = 0; I var c = str. charAt (I );
If (I = 0 ){
If (c! = "-" & (C <"0" | c> "9 ")){
Return false;
} Else if (c = "-" & str. length = 1 ){
Return false;
}
} Else if (c <"0" | c> "9 "){
Return false;
}
}
Return true;
}
/*
Returns true to indicate all English letters, and false to indicate not all English letters.
*/
Function isLetter (str ){
If ("" = str ){
Return false;
}
For (var I = 0; I var c = str. charAt (I );
If (c <"a" | c> "z") & (c <"A" | c> "Z ")){
Return false;
}
}
Return true;
}
/*
Space determines. If a space is included, false is returned. If a space is not included, true is returned.
"" Cannot be judged
*/
Function notInSpace (str ){
If ("" = str ){
Return false;
}
Var badChar = "";
BadChar + = "";
For (var I = 0; I var c = str. charAt (I); // character in string str
If (badChar. indexOf (c)>-1 ){
Return false;
}
}
Return true;
}
/*
The invoice number judgment function. If the return value is true, the return value is the invoice number. If the return value is false, the return value is invalid.
*/
Function isFPH (str ){
If ("" = str ){
Return false;
}
For (var I = 0; I var c = str. charAt (I );
If (c <"0" | c> "9") & (c! = "-") & (C! = ",")){
Return false;
}
}
Return true;
}

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.