JavaScript Library

xiaoxiao2021-03-06  77

/ *

-------------- function search -------------- TRIM function: Trim () Ltrim () RTRIM () check string is empty: CheckisNotempty (STR) check string is intellectual: Checkisinteger (STR) Check integer: Checkintegerminvalue (STR, VAL) Verification Maximum value: CheckintegerMaxValue (STR, VAL) Verification is not Negative: IsnotNegativeInteger (STR) check string is a floating point: checkisdouble (STR) check floating point minimum: CheckdoubleMinValue (STR, VAL) Check floating point maximum: CheckDoubleMaxValue (STR, VAL) Check Whether the floating point is a non-negative number: IsnotNegativeDouble (STR) check string is the date type: checkisvaliddate (STR) check two dates: checkdateearlier (strstart, strend) check string is Email: Checkemail (CHECKEMAIL) STR) Calibration string is Chinese: checkischinese (STR) calculates the length of the string, one Chinese character two characters: RealLength () check string complies with custom regular expressions: checkmask (str, pat) Suffix Name: getFilePostfix (ofile) -------------- function search -------------- * /

/ ** * added by lxcjie 2004.6.25 * Remove extra space function * Trim: remove two sides of space Ltrim: Remove left space RTRIM: Remove right space * Usage: * var str = "hello"; * str .trim () ; * / String.prototype.trim = function () {return this.replace (/ (^ [/ s *) | ([/ s] * $) / g, "");} String.Prototype.ltrim = Function () {return this.replace (/ (^ [/ s] *) / g, "");} String.Prototype.rtrim = function () {return this.replace (/ ([/ s] * $) / g, "");} / ********************** ********** EMPTY ****** ******************************************: 值 值 值 值 值 回 值 值 值 值 值 值 值 值Do not empty, define the pass, return true * If it is empty, the calibration is not passed, return false reference prompt information: The input domain cannot be empty! * / Function CheckisNotempty (STR) {IF (Str.Trim () == "") Return False; Else Return True;} // ~~~ / * --------------- ------------------ EMPTY ------------------------------- ------- * // ******************************* Integer *************** *************************************** The check string is integer * return value: * If you are empty, define the verification pass, return True * If the string is all numbers, the verification passes, return true * If the verification is not passed, return false reference prompt: The input domain must be a number! * / Function Checkisinteger (STR) {// If it is empty, the IF (Str == ") RETURN TRUE; if (/ ^ (/ -?) (/ d ) $ /. test (STR)) Return True; Else Return False;} // ~~~ / *** Verify the minimum value * Str: the string to be verified.

VAL: Value ** Return Value: * If it is empty, define the verification pass, return true * If the condition is satisfied, it is greater than or equal to the given value, the verification pass, return true * If less than a given value, return false reference prompt Information: The input field cannot be less than a given value! * / function checkintegerminvalue (STR, VAL) {// If it is empty, then pass the IF (Str == ") Return True; IF (TypeOf (VAL)! =" String ") VAL = VAL " " IF (Checkisinteger (STR) == True) {IF (Parseint (STR, 10)> = PARSEINT (VAL, 10)) Return True; Else Return False;} else returnaf false;} // ~~~ / *** Check the maximum value of * Str: string to be verified. VAL: Compare value ** Return Value: * If you are empty, define the verification pass, return true * If the condition is met, less than or equal to the given value, check True * If it is greater than the given value, return false reference prompt Information: The input value cannot be greater than the given value! * / Function checkintegermaxvalue (str, val) {// If it is empty, by verifying if (str == ") Return True; if (TypeOf (VAL)! =" String ") VAL = VAL " " IF (Checkisinteger (STR) = = True) {IF (Parseint (STR, 10) <= PARSEINT (VAL, 10)) Return True; Else Return False;} // ~~~ / *** Check if the integer is non-negative number * STR: the string to be verified.

** Return Value: * If it is empty, define the verification pass, return True * If it is not negative, return True * If it is a negative number, return false reference prompt information: The input value cannot be negative! * / Function IsnotNegativeInteger (STR) {// If it is empty, by checking if (str == ") Return True; if (Checkisinteger (STR) == True) {IF (Parseint (STR, 10) <0 } Else return true;} else return false;} // ~~~ / * -------------------------- ---- Integer -------------------------------------- * // **** ************************************************** ****************** * *** *** The check string is a floating point * return value: * If it is empty, define the verification pass, return True * If the string is a floating point, the verification is passed, return true * If the verification is not passed, return false reference prompt information: The input domain is not a legal floating point number! * / Function checkisdouble (STR) {// If it is empty, the validity IF of the integer is verified by check if (Str == ") Return True; // If is an integer, check the validity IF (Str.Indexof". ") == -1) {IF (Checkisinteger (STR) == true) Return true; else} (/ ^ (/ ^ (/ -?) (/ D ) (. {1}) (/ d ) Return true; Else Return false;}} // ~~~ / *** Verify floating point minimum * Str: string to be verified.

VAL: Value ** Return Value: * If it is empty, define the verification pass, return true * If the condition is satisfied, it is greater than or equal to the given value, the verification pass, return true * If less than a given value, return false reference prompt Information: The input field cannot be less than a given value! * / Function Checkdoubleminvalue (STR, VAL) {// If it is empty, by verifying if (str == ") Return True; if (TypeOf (VAL)! =" String ") VAL = VAL " " IF (CheckisDouble (STR) == True) {if (Parsefloat (STR)> = PARSEFLOAT (VAL)) Return True; Else Return False;} // ~~~ / *** Check floating point Maximum value * Str: The string to be verified. VAL: Compare value ** Return Value: * If you are empty, define the verification pass, return true * If the condition is met, less than or equal to the given value, check True * If it is greater than the given value, return false reference prompt Information: The input value cannot be greater than the given value! * / Function CheckDoubleMaxValue (STR, VAL) {// If it is empty, then by checking if (str == ") Return True; if (TypeOf (VAL)! =" String ") VAL = VAL " " IF (Checkisdouble (STR) == True) {if (Parsefloat (STR) <= PARSEFLOAT (VAL)) Return True; Else Return False;} // ~~~ / *** Check floating point Whether is a non-negative number * STR: the string to be verified.

** Return Value: * If it is empty, define the verification pass, return True * If it is not negative, return True * If it is a negative number, return false reference prompt information: The input value cannot be negative! * / function isnotnegativeDouble (STR) {// If it is empty, by check if (str == ") Return True; if (checkisdouble == true) {IF (Parsefloat (STR) <0) Return Else return;} // ~~~ / * ----------------------------------------------------------------------------------------------------------------------------------- - Double -------------------------- // ****** ************************************************* ********************** / / *** * Check if the string is the date * return value: * If it is empty, define the verification pass, return True * If the string is a date type, check the pass, return true * If the date is not legal, return false reference prompt information: The input field is not legal! (YYYY-mm-dd) * / function checkisvaliddate (STR) {// If it is empty, by checking if (str == ") Return True; var pattern = / ^ (/ d {4}) | (/ D {2}) - (/ D {1, 2}) - (/ D {1, 2}) $ / g; if (! pattern.test (str)) Return False; var arrdate = STR. Split ("-"); if (Paarseint (Arrdate [0], 10) <100) Arrdate [0] = 2000 PARSEINT (Arrdate [0], 10) ""; var Date = New Date (Arrdate [0 ], (Parseint (Arrdate [1], 10) -1) "" "" ", arrdate [2]); if (Date.Getfullyear () == Arrdate [0] && Date.getMonth () == (PARSEINT (Arrdate [1], 10) -1) "&& Date.getdate () == Arrdate [2]) Return True; Else Return False;} // ~~~ / *** Check Two Dates * Return Value: * If there is a date empty, check, return true * If the start date is equal to the termination date, the verification passes, return TRUE * If the start date is later than the termination date, return false reference prompt information : The start date cannot be late than the end date.

* / function checkdateearlier (strStart, strend) {if (checkisvaliddate (strStart) == false || Checkisvaliddate (strend) == false) Return false; // If there is an input is empty, then pass the IF ((strstart == "") || (strEND == ")) Return True; var arr1 = strstart.split (" - "); var arr2 = streven.split (" - "); var Date1 = new date (arr1 [0] PARSEINT (Arr1 [1] .Replace (/ ^ 0 /, "), 10) - 1, Arr1 [2]); var Date2 = new date (arr2 [0], parseint (arr2 [1] .replace / ^ 0 /, "" "", 10) - 1, Arr2 [2]); if (Arr1 [1] .length == 1) Arr1 [1] = "0" Arr1 [1]; IF (Arr1 [ 2] .length == 1) Arr1 [2] = "0" Arr1 [2]; if (Arr2 [1] .length == 1) Arr2 [1] = "0" Arr2 [1]; IF Arr2 [2] .length == 1) Arr2 [2] = "0" Arr2 [2]; var D1 = arr1 [0] arr1 [1] arr1 [2]; var D2 = arr2 [0] Arr2 [1] Arr2 [2]; IF (Parseint (D1, 10)> PARSEINT (D2, 10)) Return False; Else Return True;} // ~~~ / * --------- ------------------------------------- ---------------- * // ************************************** *** Email *************************************** / / *** Check characters Skewing is an email type * return value: * If it is empty, define the verification pass, return true * If the string is an email type, the verification is passed, return true * If Email is not legal, return false reference prompt information: email format Incorrect! * / Function Checkemail (STR) {// If it is empty, then by checking if (str == ") Return True; if (str.charat (0) ==". "|| str.charat (0) == "@" || str.indexof ('@', 0) == -1 || Str.indexof ('.'

, 0) == -1 || str.lastindexof ("@") == str.length-1 || str.lastIndexof (".") == str.length-1) Return False; else return true; // ~~~ / * ------------------------------- Email --------- ------------------------------- * // *************** ********************************************************** ******** // *** Calibration string is Chinese * return value: * If it is empty, define the verification pass, return TRUE * If the string is Chinese, check the pass, return True * If the string is non-Chinese, return false reference prompt: must be Chinese! * / Function checkischinese (STR) {// If the value is empty, by checking if (str == ") Return True; var pattern = / ^ ([/ u4e00- / u9fa5] | [/ ufe30- / uffa0] * $ / gi; if (pattern.test (str)) return true; Else Return false;} // ~~~ / ** * Calculate the length of the string, one Chinese characters * / string.prototype.reallength = function () {return this.replace (/ [^ / x00- / xff] / g, "**"). Length;} / * ----------------- ------------------------------------------------- ----- * // ****************************** Mask ************** ************************************ The check string meets custom regular expressions * STR To verify the string PAT custom regular expression * Return value: * If you are empty, define the pass, return true * If the string is in line with, return true * If the string does not match, return false Reference prompt: You must meet *** mode * / function checkmask (str, pat) {// If the value is empty, by verifying if (str == ") Return True; var pattern = new regexp (PAT," GI ") ife (Pattern.Test (STR)) Return True; Else Return False;

转载请注明原文地址:https://www.9cbs.com/read-121585.html

New Post(0)