Common JS Summary (JavaScript)

Source: Internet
Author: User
Tags rtrim
/** Function OBJ $ (ID) Get the function Val of the object based on the ID $ (ID) Get the value of the object based on the ID function trim (STR) Delete the Left and Right spaces function ltrim (STR) delete left space function rtrim (STR) delete right space function isempty (STR) string whether there is a value function equals (str1, str2) compare whether two strings are equal function equalsignorecase (str1, str2) checks whether the two strings are equal by case-insensitive. Function ischinese (STR) determines whether the Chinese function isemail (stremail) is an email function isimg (STR) whether it is a JPG file in image format | JPEG | SWF | whether giffunction isinteger (STR) is an integer F Whether the unction isfloat is a floating point function ispost (STR) whether the zip code (one to six functions ismobile (STR) is the mobile phone number function isphone (STR) whether the phone number must contain the area code, can contain extension number function isqq (STR) whether the QQ number function isip (STR) is valid ipfunction isdate (STR) whether the date type (for example, 2005-12-12) function isidcardno (idnumber) whether the ID card number is valid ** // *** replace * @ Param {object} Str * @ Param {object} oldstr * @ Param {object} newstr * @ return {typename }* /function repalce (STR, oldstr, Newstr) {var Reg = eval_r ("/" + oldstr + "/g"); Return Str. replace (Reg, newstr );} /*** truncate on the left * @ Param {object} Str * @ Param {object} n * @ return {typename} */function left (STR, n) {If (Str. length> 0) {If (n> Str. length) n = Str. length; return Str. substr (0, n) ;}else {return ;}} /*** capture at the right side * @ Param {object} Str * @ Param {object} n * @ return {typename} */function right (STR, n) {If (Str. length> 0) {if (N> = Str. length) return STR; return Str. substr (Str. length-N, N) ;}else {return ;}} function strip (STR) {If (typeof STR = 'string') return Str. replace (/^ \ s + /,''). replace (/(^ \ s *) | (\ s * $)/g, '');} function striptags (STR) {If (typeof STR = 'string ') return Str. replace (/<\/? [^>] +>/GI ,''). replace (/(^ \ s *) | (\ s * $)/g ,'');} /*** determine whether the length of a character is between S and L * @ Param {object} Str * @ Param {object} s * @ Param {object} l * @ return {typename} */function islen (STR, s, L) {STR = trim (STR) if (Str. length> S & Str. length <L) {return true;} else {return false ;}} /*** Number * @ Param {object} Str * @ return {typename} */function isnumber (STR) {If (/^ \ D + $ /. test (STR) {return true;} else {return Fals E ;}} function isletters (STR) {If (/^ [A-Za-z0-9] + $ /. test (STR) {return true;} else {return false;} function isletter (STR) {If (/^ [A-Za-Z] + $ /. test (STR) {return true;} else {return false ;}} function isupper (STR) {If (/^ [A-Z] + $ /. test (STR) {return true;} else {return false;} function islower (STR) {If (/^ [A-Z] + $ /. test (STR) {return true;} else {return false;}/*** get the object * ID: Object ID */function OBJ (ID) based on the Object ID) {return repeated E NT. getelementbyid (ID);}/*** get the value of the object based on the Object ID * ID: ID of the object */function Val (ID) {var OBJ = document. getelementbyid (ID); If (OBJ! = NULL) {return obj. value;} return NULL;}/*** remove the leading and trailing spaces of the string * STR: the string to be removed */function trim (STR) {return Str. replace (/(^ \ s *) | (\ s * $)/g, '');}/*** remove the space before the string * STR: the string */function ltrim (STR) {return Str. replace (/^ \ s */g, '');}/*** remove the space after the string * STR: the string to be removed */function rtrim (STR) {return Str. replace (/\ s * $/, '');}/*** whether the string has a value * STR: the string to be checked */function isempty (STR) {If (STR! = NULL & Str. length> 0) {return true;} return false;}/*** compare whether two strings are equal * str1: the string to be compared 1 * str2: string 2 */function equals (str1, str2) {If (str1 = str2) {return true;} return false ;} /*** ignore case-insensitive comparison of two strings for equality * str1: string to be compared 1 * str2: string to be compared 2 */function compute signorecase (str1, str2) {If (str1.touppercase () = str2.touppercase () {return true;} return false;}/*** whether it is a Chinese character * STR: string to be detected */function ischinese (STR) {var STR = Str. Replace (/(^ \ s *) | (\ s * $)/g, ''); If (! (/^ [\ U4e00-\ ufa29] * $/. Test (STR )&&(! /^ [\ Ue7c7-\ ue7f3] * $ /. test (STR) {return false;} return true;}/*** is email * STR: the string to be checked */function isemail (STR) {If (/^ [\ W-] + (\. [\ W-] +) * @ [\ W-] + (\. [\ W-] +) + $ /. test (STR) {return true} return false;}/*** is an image format file * STR: name of the file to be tested */function isimg (STR) {var objreg = new Regexp ("[.] + (JPG | JPEG | SWF | GIF) {1} quot;, "Gi"); If (objreg. test (STR) {return true;} return false;}/*** is an integer * STR: the string to be checked */function isint Eger (STR) {If (/^ -? \ D + $ /. test (STR) {return true;} return false;}/*** is a floating point number * STR: the string to be checked */function isfloat (STR) {If (/^ (-? \ D +) (\. \ D + )? $ /. Test (STR) {return true;} return false;}/*** is the zip code * STR: the string to be checked */function ispost (STR) {If (/^ \ D {1, 6} $ /. test (STR) {return true;} return false;}/*** is the mobile phone number * STR: the string to be checked */function ismobile (STR) {If (/^ 1 [35] \ D {9 }/. test (STR) {return true;} return false;}/*** whether the phone number is * STR: the string to be checked * the phone number must have a region code, possible location number */function isphone (STR) {If (/^ (0 [1-9] \ D {1, 2 }-) \ D {7, 8} (-\ D {1, 8 })? /. Test (STR) {return true;} return false;}/*** is a valid QQ number * STR: the string to be checked */function isqq (STR) {If (/^ \ D {5, 9} $ /. test (STR) {return true;} return false;}/*** is a valid IP * STR: the string to be checked */function isip (STR) {var Reg =/^ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [1-9]) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1-9] {1} [0-9] {1} | [0-9]) $/; If (Reg. test (STR) {return true;} return false;}/*** is a valid date * STR: the string to be checked */function isdate (STR) {var Reg =/^ (1 [6-9] | [2-9] \ D) \ D {2})-(0? [1, 13578] | 1 [02])-(0? [1-9] | [12] \ d | 3 [01]) | (1 [6-9] | [2-9] \ D) \ D {2})-(0? [13456789] | 1 [012])-(0? [1-9] | [12] \ d | 30) | (1 [6-9] | [2-9] \ D) \ D {2 }) -0? 2-(0? [1-9] | 1 \ d | 2 [0-8]) | (1 [6-9] | [2-9] \ D) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26]) 00)-0? 2-29-) $/; If (Reg. Test (STR) {return true;} return false ;}

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.