/*
-------------- Function retrieval --------------
Trim function: trim () lTrim () rTrim ()
Check whether the string is null: checkIsNotEmpty (str)
Check whether the string is an integer: checkIsInteger (str)
Minimum integer verification value: checkIntegerMinValue (str, val)
Maximum integer value: checkIntegerMaxValue (str, val)
Check whether the integer is non-negative: isNotNegativeInteger (str)
Check whether the string is float: checkIsDouble (str)
Verification floating point minimum value: checkDoubleMinValue (str, val)
Verification floating point maximum value: checkDoubleMaxValue (str, val)
Verify whether the floating point type is non-negative: isNotNegativeDouble (str)
Check whether the string is of the date type: checkIsValidDate (str)
Verify the order of two dates: checkDateEarlier (strStart, strEnd)
Check whether the string is email-type: checkEmail (str)
Check whether the string is Chinese: checkIsChinese (str)
Returns the length of a string. It can contain two Chinese characters: realLength ()
Check whether the string conforms to the custom Regular Expression: checkMask (str, pat)
Get the file Suffix: getFilePostfix (oFile)
-------------- Function retrieval --------------
*/
/**
* Added by LxcJie 2004.6.25
* Remove extra space functions
* Trim: Remove space on both sides lTrim: Remove left space rTrim: Remove right space
* 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 ,"");
}
/********************************** Empty **** **********************************/
/**
* Check whether the string is null.
* Return value:
* If it is not null, the verification is passed and true is returned.
* If it is null and the verification fails, false is returned. The following message is displayed: the input field cannot be blank!
*/
Function checkIsNotEmpty (str)
{
If (str. trim () = "")
Return false;
Else
Return true;
}//~~~
/* ----------------------------------- Empty --------------------------------------*/
/********************************* Integer **** *********************************/
/**
* Check whether the string is an integer.
* Return value:
* If it is null, the verification is passed and true is returned.
* If all strings are numbers, true is returned if the verification succeeds.
* If the verification fails, false is returned. The following message is displayed: the input field must be a number!
*/
Function checkIsInteger (str)
{
// If it is null, it passes verification.
If (str = "")
Return true;
If (/^ (\\-?) (\ D +) $/. test (str ))
Return true;
Else
Return false;
}//~~~
/**
* Verify the minimum integer value
* Str: string to be verified. Val: the value to be compared.
*
* Return value:
* If it is null, the verification is passed and true is returned.
* If the conditions are met and the value is greater than or equal to the given value, true is returned if the verification succeeds.
* If the value is less than the given value, false is returned. Reference prompt: the input field cannot be less than the given value!
*/
Function checkIntegerMinValue (str, val)
{
// If it is null, it passes verification.
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
Return false;
}//~~~
/**
* Verify the maximum integer value
* Str: string to be verified. Val: the value to be compared.
*
* Return value:
* If it is null, the verification is passed and true is returned.
* If the conditions are met and the value is less than or equal to the given value, true is returned if the verification succeeds.
* If the value is greater than the given value, false is returned. The input value cannot be greater than the given value!
*/
Function checkIntegerMaxValue (str, val)
{
// If it is null, it passes verification.
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
Return false;
}//~~~
/**
* Check whether the integer is non-negative.
* Str: string to be verified.
*
* Return value:
* If it is null, the verification is passed and true is returned.
* If it is not a negative number, true is returned.
* If it is a negative number, false is returned. The input value cannot be a negative number!
*/
Function isNotNegativeInteger (str)
{
// If it is null, it passes verification.
If (str = "")
Return true;
If (checkIsInteger (str) = true)
{
If (parseInt (str, 10) <0)
Return false;
Else
Return true;
}
Else
Return false;
}//~~~
/* ----------------------------------- Integer --------------------------------------*/
/********************************** Double **** ************************************/
/**
* Check whether the string is float.
* Return value:
* If it is null, the verification is passed and true is returned.
* If the string is float, true is returned if the verification succeeds.
* If the verification fails, false is returned. The following message is displayed: the input field is not a valid floating point number!
*/
Function checkIsDouble (str)
{
// If it is null, it passes verification.
If (str = "")
Return true;
// If the value is an integer, the validity of the integer is verified.
If (str. indexOf (".") =-1)
{
If (checkIsInteger (str) = true)
Return true;
Else
Return false;
}
Else
{
If (/^ (\\-?) (\ D +) (. {1}) (\ d +) $/g. test (str ))
Return true;
Else
Return false;
}
}//~~~
/**
* Verify the floating point minimum value
* Str: string to be verified. Val: the value to be compared.
*
* Return value:
* If it is null, the verification is passed and true is returned.
* If the conditions are met and the value is greater than or equal to the given value, true is returned if the verification succeeds.
* If the value is less than the given value, false is returned. Reference prompt: the input field cannot be less than the given value!
*/
Function checkDoubleMinValue (str, val)
{
// If it is null, it passes verification.
If (str = "")
Return true;
If (typeof (val )! = "String ")
Val = val + "";
If (checkIsDouble (str) = true)
{
If (parseFloat (str)> = parseFloat (val ))
Return true;
Else
Return false;
}
Else
Return false;
}//~~~
/**
* Verify the Floating Point Maximum Value
* Str: string to be verified. Val: the value to be compared.
*
* Return value:
* If it is null, the verification is passed and true is returned.
* If the conditions are met and the value is less than or equal to the given value, true is returned if the verification succeeds.
* If the value is greater than the given value, false is returned. The input value cannot be greater than the given value!
*/
Function checkDoubleMaxValue (str, val)
{
// If it is null, it passes verification.
If (str = "")
Return true;
If (typeof (val )! = "String ")
Val = val + "";
If (checkIsDouble (str) = true)
{
If (parseFloat (str) <= parseFloat (val ))
Return true;
Else
Return false;
}
Else
Return false;
}//~~~
/**
* Check whether the floating point type is non-negative.
* Str: string to be verified.
*
* Return value:
* If it is null, the verification is passed and true is returned.
* If it is not a negative number, true is returned.
* If it is a negative number, false is returned. The input value cannot be a negative number!
*/
Function isNotNegativeDouble (str)
{
// If it is null, it passes verification.
If (str = "")
Return true;
If (checkIsDouble (str) = true)
{
If (parseFloat (str) <0)
Return false;
Else
Return true;
}
Else
Return false;
}//~~~
/* --------------------------------- Double ---------------------------------------*/
/********************************** Date **** **************************************/
/**
* Check whether the string is of the date type.
* Return value:
* If it is null, the verification is passed and true is returned.
* If the string is of the date type and the verification succeeds, true is returned.
* If the date is invalid, false is returned. The following message is displayed: The time of the input domain is invalid! (Yyyy-MM-dd)
*/
Function checkIsValidDate (str)
{
// If it is null, it passes 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 (parseInt (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;
}//~~~
/**
* Verify the order of two dates
* Return value:
* If one of the dates is null and the verification succeeds, true is returned.
* If the start date is earlier than or equal to the end date, the system returns true if the verification is successful.
* If the start date is later than the end date, false is returned. Reference message: the start date cannot be later than the end date.
*/
Function checkDateEarlier (strStart, strEnd)
{
If (checkIsValidDate (strStart) = false | checkIsValidDate (strEnd) = false)
Return false;
// If one input is null, it passes the test.
If (strStart = "") | (strEnd = ""))
Return true;
Var arr1 = strStart. split ("-");
Var arr2 = strEnd. 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;
}//~~~
/* ----------------------------------- Date -----------------------------------------*/
/********************************** Email **** *************************************/
/**
* Check whether the string is email-type.
* Return value:
* If it is null, the verification is passed and true is returned.
* If the string is of the email type and the verification is successful, true is returned.
* If the email is invalid, false is returned. Refer to the prompt message: the Email format is incorrect!
*/
Function checkEmail (str)
{
// If it is null, it passes 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;
}//~~~
/* ----------------------------------- Email ----------------------------------------*/
**** ***********************************/
/**
* Check whether the string is Chinese
* Return value:
* If it is null, the verification is passed and true is returned.
* If the string is Chinese, true is returned if the verification succeeds.
* If the string is not Chinese, false is returned. The reference prompt is "Chinese!
*/
Function checkIsChinese (str)
{
// If the value is null, it passes verification.
If (str = "")
Return true;
Var pattern =/^ ([\ u4E00-\ u9FA5] | [\ uFE30-\ uFFA0]) * $/gi;
If (pattern. test (str ))
Return true;
Else
Return false;
}//~~~
/**
* Calculates the length of a string, one Chinese Character and two characters
*/
String. prototype. realLength = function ()
{
Return this. replace (/[^ \ x00-\ xff]/g, "**"). length;
}
/* ----------------------------------- Chinese --------------------------------------*/
/********************************** Mask **** ***********************************/
/**
* Check whether the string meets the custom regular expression.
* Str: the string pat custom regular expression to be verified
* Return value:
* If it is null, the verification is passed and true is returned.
* True is returned if the string matches and the verification succeeds.
* If the string does not match, false is returned. The following message is displayed: The ** mode must be met.
*/
Function checkMask (str, pat)
{
// If the value is null, it passes verification.
If (str = "")
Return true;
Var pattern = new RegExp (pat, "gi ")
If (pattern. test (str ))
Return true;
Else
Return false;
}//~~~
/* ----------------------------------- Mask --------------------------------------*/
/********************************** File **** ***********************************/
/**
* Added by LxcJie 2004.6.25
* Get the file suffix
* OFile is a file control object.
*/
Function getFilePostfix (oFile)
{
If (oFile = null)
Return null;
Var pattern =/(. *) \. (. *) $/gi;
If (typeof (oFile) = "object ")
{
If (oFile. value = null | oFile. value = "")
Return null;
Var arr = pattern.exe c (oFile. value );
Return RegExp. $2;
}
Else if (typeof (oFile) = "string ")
{
Var arr = pattern.exe c (oFile );
Return RegExp. $2;
}
Else
Return null;
}//~~~