Java SDK Library

Source: Internet
Author: User
Tags rtrim

/*

-------------- 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;
}//~~~
/* ----------------------------------- File --------------------------------------*/
 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx? Postid = 1420283

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.