/ *
-------------- 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 ( STR)
The 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) : GetFilePostfix (ofile) -------------- Function Retrieval -------------- * /
/ *** 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 ** ************************************ / / *** Check if the check string is empty * return Value: * If not empty, define the verification pass, return true * If it is empty, the verification is not passed, return false reference prompt information: The input field 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;} // ~~~ / *** Check 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 Return False;} else {= (/ ^ (// -?) (// d ) (. {1}) //d ) $/g.test(Str) Return True; Else Return false;}} // ~~~ / *** Check floating point minimum * STR: Strings 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 CheckisvaliddDate (STR) {// If it is empty, then by check 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.GetyEAR () == Arrdate [0] && Date.getMonth () == (PARSEINT (Arrdate [1], 10) -1) "&& Date.getdate () == Arrdate [2]) Return True; Else Return False;} // ~~~ / *** Check two Date of the date * return value: * If there is a date is empty, the verification is passed, return to 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 Tips: 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 check if (str == ") Return True; var pattern = / ^ ([// u4e00 - //////////////// UFE30- // uffa0]) * $ / gi; if (pattern.test (str)) Return true; Else Return false;} // ~~~ / *** Calculate the length of the string, one Chinese character * / String .prototype.reallength = function () {Return this.replace (/ [^ // x00 - // xff] / g, "**"). Length;} / * ----------- --------------------------------------------------- ----------- * // ***************************************** Mask * ************************************************************************************* Defining regular expressions * STR To check string PAT Custom regular expression * Return Value: * If you are empty, define the verification pass, return true * If the string is in line with, the verification is passed, return true * if word The string does not match, return false reference prompt: must satisfy *** mode * / function checkmask (str, pat) {// If the value is empty, pass the IF (STR == ") Return True; var pattern = New regexp (PAT, "GI") ing (Pattern.Test (STR)) Return True; Else Return False;