Object-oriented ASP programming 3-some common functions

Source: Internet
Author: User

<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>

 

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.