Javascript tool class (determining leap year, Chinese characters, IP addresses, precision, etc ..)

Source: Internet
Author: User
Remove spaces at the beginning and end, check whether the string contains Chinese characters, open a new window, verify the IP address, normalize the floating point number to the specified precision, and determine whether the provided string is empty, determines whether the provided string is an integer, whether the input character is capital or a letter, whether the input character is 0-9 numeric, whether the provided string contains only numeric characters, and whether a leap year is supported)
/*************************************** **************************************** * ***** Name: existchinese (strvalue) function: This function is used to check whether the string contains the Chinese character parameter: strvalue --- input parameter; string; the string to be processed returns a Boolean value; true -- contains Chinese characters; false -- do not include Chinese character reference: no description: **************************************** **************************************** * *****/function existchinese (strvalue) {var chrcodefor (VAR ichar = 0; ichar <strvalue. length; ichar ++) {chrcode = strvalue. charcodeat (ichar); If (parseint (chrcode)> 255) {return true ;}} return false ;}
/*************************************** **************************************** * *** Open a new window */function OpenWindow (I _url, I _width, I _height) {OpenWindow (I _url, I _width, I _height, null, null);} function OpenWindow (I _url, I _width, I _height, I _feature) {OpenWindow (I _url, I _width, I _height, null, I _feature);} function OpenWindow (I _url, I _width, I _height, I _windowname, I _feature) {var v_url = I _url; var V_width = I _width; var v_height = I _height; var v_windowname = I _windowname; var v_top; var v_left; var v_feature = ""; if (v_windowname = NULL) {v_windowname = "mywindow";} var objwindow if (! Objwindow | objwindow. closed) {v_top = screen. availheight/2-v_height/2-30; v_left = screen. availwidth/2-v_width/2; v_feature + = "Top =" + v_top + ","; v_feature + = "Left =" + v_left + ","; v_feature + = "width =" + v_width + ","; v_feature + = "Height =" + v_height + ","; if (I _feature = NULL) {v_feature + = "directories = No, fullscreen = No, resizable = No, scrollbars = Yes, status = 1";} else {v_feature + = I _feature;} objwindow = Window. open (v_url, v_windowname, v_feature); // objwindow = Window. open (v_url, v_windowname, "directories = No, fullscreen = No, resizable = No, scrollbars = No, status = 1"); // v_top = screen. availheight/2-v_height/2; // v_left = screen. availwidth/2-v_width/2; // objwindow. moveTo (v_left, v_top); // objwindow. resizeTo (v_width, v_height); objwindow. outerwidth = screen. availwidth; objwindow. outerheight = screen. availheight-25;} else {objwindow. focus ();} objwindow. focus ();}
/*************************************** **************************************** * ***** Name: trim (strvalue) function: This function is used to remove the space parameter before and after the string: strvalue --- input parameter; string; the string to be processed returns: String reference: no description: if it is a space string, the system returns a blank ********************************* **************************************** * ************/function trim (strvalue) {var iltr, jrtl; var CHR; // remove the spaces before and after the string for (iltr = 0; iltr <strvalue. length; iltr ++) {CHR = strvalue. charat (iltr) ; If (CHR! = "") Break;} If (iltr = strvalue. length) Return ""; // remove the spaces before and after the string for (jrtl = strvalue. length-1; jrtl> = 0; jrtl --) {CHR = strvalue. charat (jrtl); If (CHR! = "") Break;} return strvalue. substring (iltr, jrtl + 1 );}
/** Verify IP */function checkip (strip) {If (isempty (strip) return false; var Re =/^ (\ D + )\. (\ D + )\. (\ D + )\. (\ D +) $/g // The regular expression that matches the IP address if (Re. test (strip) {If (Regexp. $1 <256 & Regexp. $2 <256 & Regexp. $3 <256 & Regexp. $4 <256) return true;} return false ;}
/*** Regular floating point number to the specified precision * @ pram original_number original Floating Point Number * @ pram decimals result decimal point value * @ return regular floating point number */function round_decimals (original_number, decimals) {var result1 = original_number * Math. pow (10, decimals); var result2 = math. round (result1); var result3 = result2/math. pow (10, decimals); Return (result3 );}
/*** Determine whether the provided string is null * @ Param field input string * @ return true/false */function isempty (field) {return (field = NULL) | (field. length = 0) | mytrim (field) = "");} /*** determine whether the provided string is an integer * @ Param field input string * @ return true/false */function isinteger (field) {S = mytrim (field ); vaR I; If (isempty (field) {return false;} for (I = 0; I <field. length; I ++) {var c = field. charat (I); If (! Isdigit (c) {return false;} If (C = 0 & I = 0 & field. length> 1) {return false;} return true ;} /*** determine whether the input character is uppercase or letter * @ Param C input character * @ return true/false */function isletter (c) {return (C> = "A") & (c <= "Z") | (C> = "") & (c <= "Z ")));} /*** determine whether the input character is a 0-9 numeric character * @ Param C input character * @ return true/false */function isdigit (c) {return (C> = "0") & (c <= "9 "));}
/*** Determine that the provided string contains only numeric characters * @ Param field input string * @ return true/false */function isnumbers (field) {field = mytrim (field ); vaR I; for (I = 0; I <field. length; I ++) {var c = field. charat (I); If (! Isdigit (c) {return false;} return true ;}
/*** Determine the leap year * @ Param s year @ return true/false **/function isrunnian (s) {// alert (S % 4); If (S % 4! = 0) {return false;} else {If (S % 100! = 0) {return true;} else {If (S % 400 = 0) {return true;} else {return false ;}}}}
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.