<Script language = JavaScript runat = Server>
//************************************** **********************************
// Script compont Object Model
// Design for Active Server Pages
//
// Copyright 2003 version 1.0
// Made by yinshuguang
//************************************** **********************************
Function trim (STR) // remove the spaces at the beginning and end of the string
{Var tmpstr = new string (STR)
Return tmpstr. Replace (/(^/S *) | (/S * $)/g ,"");
}
Function checklength (STR, minlength, maxlength) // check whether the length of the string is within the permitted range.
{
VaR strtemp = new string (STR );
If (minlength> maxlength ){
VaR tempint = maxlength
Maxlength = minlength;
Minlength = tempint
}
If (strtemp. Length <= maxlength & strtemp. length> = minlength ){
Return true;
}
Else {
Return false;
}
}
Function checkemail (STR) // check whether the string has the @ symbol
{
VaR stremail = new string (STR)
VaR ihaveat = 0;
VaR ihavedot = 0;
For (VAR I = 0; I <stremail. length; I ++)
{
If (stremail. charat (I) = "@"){
Ihaveat ++;
}
If (stremail. charat (I) = "."){
Ihavedot ++;
}
}
If (ihaveat = 1) & (ihavedot! = 0 )){
Return true;
}
Else {
Return false;
}
}
Function fixin (MDL, STR) {// check whether each character in STR is one of the MDL
VaR isign = 0;
For (VAR I = 0; I <Str. length; I ++ ){
For (var j = 0; j <MDL. length; j ++ ){
If (Str. charat (I) = MDL. charat (j )){
Isign = 1;
Break;
}
Else {
Isign = 0;
}
}
If (isign = 0 ){
Break;
}
}
If (isign = 1 ){
Return true;
}
Else {
Return false;
}
}
Function isnumber (STR) {// check whether the string is composed of digits
VaR MDL = newstring ("0123456789 ");
If (fixin (MDL, STR )){
Return true;
}
Else {
Return false;
}
}
Function istelephone (STR) {// check whether the string is composed of phone numbers
VaR MDL = newstring ("0123456789 -");
If (fixin (MDL, STR )){
Return true;
}
Else {
Return false;
}
}
Function isfloat (STR) {// check whether the string is composed of floating point numbers.
VaR MDL = new string ("0123456789 .");
If (fixin (MDL, STR )){
Return true;
}
Else {
Return false;
}
}
Function getrandomstr () {// returns a 15-bit random string.
VaR ranstr = New String
VaR d = new date
VaR X, Y
Ranstr = D. valueof ()
X = math. Random ()
X = x * 100
X = math. Round (X)
X = (x> = 99 )? X-1: x
X = (x <10 )? X + 10: x
Ranstr + = x. tostring ()
Return ranstr
}
</SCRIPT>