JavaScript Library
/ *
-------------- Function Retrieval --------------
Trim function: Trim () Ltrim () RTRIM ()
Check whether the string is empty: CheckisNotempty (STR)
Check if the check string is integer: Checkisinteger (STR)
Verify the minimum: Checkintegerminvalue (Str, VAL)
Verify the maximum value of CheckintegerMaxValue (Str, VAL)
Check if the integer is non-negative number: IsnotNegativeInteger (STR)
Whether the check string is a floating point: Checkisdouble (STR)
Check floating point minimum: Checkdoubleminvalue (Str, VAL)
Verify floating point maximum: CheckdoubleMaxValue (Str, VAL)
Check if the floating point is non-negative number: IsnotNegativeDouble (STR)
Calibration string is dated: Checkisvaliddate (STR)
Check two dates: CheckdateEarlier (strStart, Strend)
Check if the string is Email type: Checkemail (STR)
Whether the check string is Chinese: CheckisCHINESE (STR)
Calculate the length of the string, one Chinese character two characters: Reallength ()
Calibration strings comply with custom regular expressions: Checkmask (STR, PAT)
Get the name of the file: getfilepostfix (ofile)
-------------- Function Retrieval --------------
* /
/ **
* Added by lxcjie 2004.6.25
* Remove extra space function
* TRIM: Remove both sides of space Ltrim: Remove left space RTRIM: Remove right spaces
* Usage:
* Var str = "hello";
* Str = 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, "");
}
/ ************************ ************************* *********************** /
/ **
* Verify whether the string is empty
*return value:
* If it is not empty, define the verification pass, return to TRUE
* If it is empty, the verification 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;
} // ~~~
/ * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------ * /
/ ********************** Integer ************** ********************** /
/ **
* Calibration string is integer
*return value:
* If it is empty, define the verification pass, return true
* If the strings are all numbers, check the pass, return true
* If the verification is not passed, return false reference prompt information: The input domain must be a number!
* /
Function Checkisinteger (STR)
{
// If it is empty, pass the verification
IF (str == "")
Return True;
IF (/ ^ (/ -?) (/ d ) $ /. TEST (STR))
Return True;
Else
Return False;
} // ~~~
/ **
* Verify the minimum value
* STR: The string to be verified. VAL: compare value
*
*return value:
* If it is empty, define the verification pass, return true
* If the condition is met, it is greater than or equal to the give value, check the pass, return true
* If less than a given value, return false reference prompt information: The input field cannot be less than the given value!
* /
Function Checkintegerminvalue (Str, VAL)
{
// If it is empty, pass the verification
IF (str == "")
Return True;
IF (TypeOf (VAL)! = "String")
VAL = VAL ""
Checkisinteger (STR) == True)
{
IF (PARSEINT (STR, 10)> = PARSEINT (VAL, 10))
Return True;
Else
Return False;
}
Else
Return False;
} // ~~~
/ **
* Verify the maximum value
* STR: The string to be verified. VAL: compare value
*
*return value:
* If it is empty, define the verification pass, return true
* If the condition is met, less than or equal to give the value, check the pass, return TRUE
* If it is greater than a 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, pass the verification
IF (str == "")
Return True;
IF (TypeOf (VAL)! = "String")
VAL = VAL ""
Checkisinteger (STR) == True)
{
IF (Parseint (STR, 10) <= PARSEINT (VAL, 10))
Return True;
Else
Return False;
}
Else
Return false;} // ~~~
/ **
* Calibration is a non-negative number
* STR: The string to be verified.
*
*return value:
* If it is empty, define the verification pass, return true
* If you are 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, pass the verification
IF (str == "")
Return True;
Checkisinteger (STR) == True)
{
IF (Parseint (STR, 10) <0)
Return False;
Else
Return True;
}
Else
Return False;
} // ~~~
/ * ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------ * /
/ *********************** DOUBLE ************** ********************************** /
/ **
* Calibration string is a floating point
*return value:
* If it is empty, define the verification pass, return true
* If the string is a floating point, check the pass, 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, pass the verification
IF (str == "")
Return True;
// If it is an integer, the validity of the correction integer
IF (str.indexof (") == -1)
{
Checkisinteger (STR) == True)
Return True;
Else
Return False;
}
Else
{
IF (/ ^ (/ -) (/ d ) (. {1}) (/ d ) $ / g.test (str))
Return True;
Else
Return False;
}
} // ~~~
/ **
* Check the smallest value of floating point
* STR: The string to be verified. VAL: compare value
*
*return value:
* If it is empty, define the verification pass, return true
* If the condition is met, it is greater than or equal to the give value, check the pass, return true
* If less than a given value, return false reference prompt information: The input field cannot be less than the given value!
* /
Function Checkdoubleminvalue (Str, VAL)
{
// If it is empty, pass the verification
IF (str == "")
Return True;
IF (TypeOf (VAL)! = "String")
VAL = VAL ""
Checkisdouble (STR) == True)
{
IF (Parsefloat (STR)> = Parsefloat (VAL))
Return True;
Elsereturn False;
}
Else
Return False;
} // ~~~
/ **
* Check the floating point maximum
* STR: The string to be verified. VAL: compare value
*
*return value:
* If it is empty, define the verification pass, return true
* If the condition is met, less than or equal to give the value, check the pass, return TRUE
* If it is greater than a 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, pass the verification
IF (str == "")
Return True;
IF (TypeOf (VAL)! = "String")
VAL = VAL ""
Checkisdouble (STR) == True)
{
IF (Parsefloat (STR) <= PARSEFLOAT (VAL))
Return True;
Else
Return False;
}
Else
Return False;
} // ~~~
/ **
* Check if the floating point is non-negative number
* STR: The string to be verified.
*
*return value:
* If it is empty, define the verification pass, return true
* If you are 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, pass the verification
IF (str == "")
Return True;
Checkisdouble (STR) == True)
{
IF (Parsefloat (STR) <0)
Return False;
Else
Return True;
}
Else
Return False;
} // ~~~
/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------- * /
/ ************************************************ *************************** /
/ **
* Verify whether the string is a date type
*return value:
* If it is empty, define the verification pass, return true
* If the string is a date, check, 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, pass the verification
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 (paraSeint (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.GetyEAR () == 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 one of the dates, check the pass, return TRUE
* If the start date is equal to the termination date, check the pass, return to 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 verify
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;
} // ~~~
/ * ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------- * /
/ ************************************************* ************************** // **
* Calibration string is email type
*return value:
* If it is empty, define the verification pass, return true
* If the string is an Email type, check the pass, return true
* If Email is not legal, return false reference prompt information: email's format is incorrect!
* /
Function Checkemail (STR)
{
// If it is empty, pass the verification
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;
} // ~~~
/ * ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------- /
/ ************************************************ ************************ /
/ **
* 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 to TRUE
* If the string is non-Chinese, return false reference prompt: must be Chinese!
* /
Function CheckisChinese (STR)
{
// If the value is empty, pass the verification
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 character two characters
* /
String.Prototype.RealLength = function ()
{
Return this.Replace (/ [^ / X00- / XFF] / g, "**"). Length;
}
/ * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------ * /
/ *********************** Mask *************** ************************ /
/ **
* Verify whether the string meets custom regular expressions
* Str's string PAT custom regular expressions
*return value:
* If you are empty, define the verification pass, return true * If the string is in line with, the verification is passed, return to TRUE
* If the string does not match, return false reference prompt information: must be met *** mode
* /
Function Checkmask (STR, PAT)
{
// If the value is empty, pass the verification
IF (str == "")
Return True;
Var pattern = new regexp (PAT, "GI")
IF (Pattern.Test (STR))
Return True;
Else
Return False;
} // ~~~
/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------ * /
/ ******************************** File *************** ************************ /
/ **
* Added by lxcjie 2004.6.25
* Get the name of the file
* Ofile is the File control object
* /
Function getFilePostfix (Ofile)
{
IF (ofile == NULL)
Return NULL;
Var pattern = /(.*) /. (.*) $/gi;
IF (typeof) == "Object")
{
IF (Ofile.Value == Null || OFLE.VALUE == "")
Return NULL;
VAR arr = pattern.exec (ofile.value);
Return Regexp. $ 2;
}
Else if (typeof (ofile) == "String")
{
Var arr = pattern.exec (OFILE);
Return Regexp. $ 2;
}
Else
Return NULL;
} // ~~~
/ * ------------------------------------------------------------------------------------------- ------------------------ * /