// 15
//-------------------------------------
// The content is between two values
// + ------------------------------------
Function letmid (OBJ, leftnumber, rightnumber, hintflag, focusflag)
{
VaR ifalert; // whether a warning is reported
If (g_obj = NULL)
G_obj = event. srcelement;
Else if (g_obj! = NULL) & (hintflag = 0) & (g_obj! = OBJ ))
{
G_obj = NULL;
Return;
}
G_obj.value = g_obj.value.trim ();
If (g_obj.value = "")
Ifalert = 0;
Else
Ifalert = 1;
// It should be a number first
If (letnumber (g_obj, 1 ))
{
If (! (Letmorethan (OBJ, leftnumber,) & letlessthan (OBJ, rightnumber )))
{
If (hintflag = 0)
{
G_obj.value = "";
If (focusflag = 1)
G_obj.focus ();
Else
G_obj = NULL;
If (ifalert = 1) // when the user does not enter the data, no prompt is displayed.
Alert ("the input content must be between" + leftnumber + "and" + rightnumber +! ");
}
Return false;
}
Else
{G_obj = NULL ;}
}
Else
{
If (hintflag = 0)
{
G_obj.value = "";
If (focusflag = 1)
G_obj.focus ();
Else
G_obj = NULL;
If (ifalert = 1)
Alert ("the input content must be a number! /N "+
"And between" + leftnumber + "and" + rightnumber +! ");
}
Return false;
}
Return true;
}
//-------------------------------------
/////////////////////////////////////////
// Drop-down list
/////////////////////////////////////////
// In the drop-down list, be sure to select
// + ------------------------------------
Function onsellostfocus (OBJ)
{
If (g_obj = NULL)
{
G_obj = event. srcelement;
}
Else if (g_obj! = NULL) & (g_obj! = OBJ ))
{
G_obj = NULL;
Return;
}
If (g_obj.selectedindex = 0)
{
G_obj.focus ();
}
Else
{
G_obj = NULL;
}
}
/*
, Wind JavaScript function library
Add the tested function to the database.
*/
/********************
Function Name: strlenthbyte
Function: Calculate the length of a string in two bytes.
Function parameter: Str, which is the string to be calculated.
********************/
Function strlenthbybyte (STR)
{
VaR Len;
VaR I;
Len = 0;
For (I = 0; I <Str. length; I ++)
{
If (Str. charcodeat (I)> 255) Len + = 2; else Len ++;
}
Return Len;
}
/********************
Function Name: isemailaddress
Function: checks the validity of the email address. If the email address is valid, true is returned. Otherwise, false is returned.
Function parameter: OBJ, email address to be checked
********************/
Function isemailaddress (OBJ)
{
VaR pattern =/^ [a-zA-Z0-9/-] + @ [a-zA-Z0-9/-/.] +/. ([A-Za-Z] {2, 3}) $ /;
If (pattern. Test (OBJ ))
{
Return true;
}
Else
{
Return false;
}
}
/********************
Function Name: popwindow
Function: a new window is displayed.
Function parameters: pageurl, new window address; winwidth, window width; winheight, window height
********************/
Function popwindow (pageurl, winwidth, winheight)
{
VaR popwin = Window. Open (pageurl, "popwin", "scrollbars = Yes, toolbar = No, location = No, directories = No
, Status = No, menubar = No, resizable = No, width = "+ winwidth +", Height = "+ winheight );
Return false;
}
/********************
Function Name: popremotewindow
Function: the original process window that controls the parent form is displayed.
Function parameters: pageurl, new window address;
Call method: Open the window: <a href = "javascript: popremotewindow (URL);"> open </a>
Control the parent form: opener. Location = URL; of course, there can be other control
********************/
Function popremotewindow (pageurl)
{
VaR remote = Window. Open (URL, "remotewindow", "scrollbars = Yes, toolbar = Yes, location = Yes,
Directories = Yes, status = Yes, menubar = Yes, resizable = yes ");
If (remote. Opener = NULL)
{
Remote. Opener = window;
}
}
/********************
Function Name: istelephone
Function: fixed-line phone number check function. Valid return value: True. Otherwise, false is returned.
Function parameter: OBJ, number to be checked
Check rules:
(1) Telephone Numbers consist of numbers, "(", ")", and "-"
(2) 3 to 8 phone numbers
(3) If the telephone number contains a district code, the district code is three or four digits.
(4) area codes are separated by "(", ")" or "-" and other sections.
(5) the mobile phone number is 11 or 12 digits. If the mobile phone number is 12 digits, the first digit is 0.
(6) The first and second digits of 11 mobile phone numbers are "13"
(7) The second and third digits of the 12-digit mobile phone numbers are "13"
********************/
Function istelephone (OBJ)
{
VaR pattern =/(^ [0-9] {3, 4}/-[0-9] {3, 8} $) | (^ [0-9] {3, 8} $) | (^/([0-9] {3, 4}/) [0-9] {3, 8} $) | (^ 0 {0, 1} 13 [0-9] {9} $ )/;
If (pattern. Test (OBJ ))
{
Return true;
}
Else
{
Return false;
}
}
/********************
Function Name: islegality
Function: checks the validity of a string, that is, whether it contains the "'character. if it contains the character, false is returned. Otherwise, true is returned.
Function parameter: OBJ, the string to be checked
********************/
Function islegality (OBJ)
{
VaR intcount1 = obj. indexof ("/" ", 0 );
VaR intcount2 = obj. indexof ("/'", 0 );
If (intcount1> 0 | intcount2> 0)
{
Return false;
}
Else
{
Return true;
}
}
/********************
Function Name: isnumber
Function: checks whether all strings are numbers.
Function parameter: Str, the string to be checked
********************/
Function isnumber (STR)
{
VaR number_chars = "1234567890 ";
VaR I;
For (I = 0; I <Str. length; I ++)
{
If (number_chars.indexof (Str. charat (I) =-1) return false;
}
Return true;
}
/********************
Function Name: trim
Function: removes spaces on both sides of a string.
Function parameter: Str, string to be processed
********************/
Function trim (STR)
{
Return Str. Replace (/(^/S *) | (/S * $)/g ,"");
}
/********************
Function Name: ltrim
Function: Remove spaces on the left.
Function parameter: Str, string to be processed
********************/
Function ltrim (STR)
{
Return Str. Replace (/(^/S *)/g ,"");
}
/********************
Function Name: rtrim
Function: Remove spaces on the right.
Function parameter: Str, string to be processed
********************/
Function rtrim (STR)
{
Return this. Replace (/S * $)/g ,"");
}
/********************
Function Name: isnull
Function: determines whether a given string is null.
Function parameter: Str, string to be processed
********************/
Function isnull (STR)
{
If (TRIM (STR) = "")
{
Return false;
}
Else
{
Return true;
}
}
/********************
Function Name: cookieenabled
Function: determines whether the cookie is enabled.
********************/
Function cookieenabled ()
{
Return (navigator. cookieenabled )? True: false;
}
/* String replacement method */
Function strreplace (srcstring, findstring, replacestring, start)
{
// Code
}
/* Client HTML encoding */
Function htmlencode (STR)
{
// Code
}
/*************************************** *****************************
**
* Function: determines whether it is a leap year *
* Input parameter: numeric string *
* Return value: True, which is a leap year or false. Others *
* Call a function :*
**
**************************************** ****************************/
Function isleapyear (iyear)
{
If (iyear + "" = "undefined" | iyear + "" = "null" | iyear + "" = "")
Return false;
Iyear = parseint (iyear );
Varisvalid = false;
If (iyear % 4 = 0 & iyear % 100! = 0) | iyear % 400 = 0)
Isvalid = true;
Return isvalid;
}
/*************************************** *****************************
**
* Function: retrieve the last day of a specified year or month *
* Input parameter: year, month *
* Return value: the last day of a month *
* Call the function: isleapyear *
**
**************************************** ****************************/
Function getlastday (iyear, Imonth)
{
Iyear = parseint (iyear );
Imonth = parseint (Imonth );
Variday = 31;
If (Imonth = 4 | Imonth = 6 | Imonth = 9 | Imonth = 11) & iday = 31)
Iday = 30;
If (Imonth = 2)
If (isleapyear (iyear ))
Iday = 29;
Else
Iday = 28;
Return iday;
}
/*************************************** *****************************
**
* Function: removes the null header and tail of a string *
* Input parameter: string *
* Return value: String/null. If the input string is incorrect *
* Call functions: trimleft () and trimright ()*
**
**************************************** ****************************/
Function trim (STR)
{
Varresultstr = "";
Resultstr = trimleft (STR );
Resultstr = trimright (resultstr );
Return resultstr;
}
/*************************************** *****************************
**
* Function: removes the null character string header *
* Input parameter: string *
* Return value: String/null. If the input string is incorrect *
* Call a function :*
**
**************************************** ****************************/
Function trimleft (STR)
{
Varresultstr = "";
Vari = Len = 0;
If (STR + "" = "undefined" | STR = NULL)
Return NULL;
STR + = "";
If (Str. Length = 0)
Resultstr = "";
Else
{
Len = Str. length;
While (I <= Len) & (Str. charat (I) = ""))
I ++;
Resultstr = Str. substring (I, Len );
}
Return resultstr;
}