ASP应用中的应用函数2

11.控制输出字符串的长度,可以区别中英文 
  函数在下面,是方法是: 
  strvalue("复请Email通知如果不填写则取注册Email",26) 
  这里26是指26个英文字母,也就是13个汉字 
function strlen(str) 
dim p_len 
p_len=0 
strlen=0 
if trim(str)<>"" then 
p_len=len(trim(str)) 
for xx=1 to p_len 
if asc(mid(str,xx,1))<0 then 
strlen=int(strlen) + 2 
else 
strlen=int(strlen) + 1 
end if 
next 
end if 
end function 

function strvalue(str,lennum) 
dim p_num 
dim i 
if strlen(str)<=lennum then 
strvalue=str 
else 
p_num=0 
x=0 
do while not p_num > lennum-2 
x=x+1 
if asc(mid(str,x,1))<0 then 
p_num=int(p_num) + 2 
else 
p_num=int(p_num) + 1 
end if 
strvalue=left(trim(str),x)&"…" 
loop 
end if 
end function 


12.一个把数字转英文的实用程序 
  原数字格式:2000 
  格式化后:TWO THOUSAND ONLY 
  引用: 
  自定义函数: 


 

13.把长的数字用逗号隔开显示 
  文字格式:12345678 
  格式化数字:12,345,678 
  自定义函数: 

 

 

  引用: 
 


14.随机生成文件名的函数 
 


15.每行显示n个字母,自动换行  

Function rowscode(str,n)  
If len(str)<=n/2 Then  
rowscode=str  
Else  
Dim TStr  
Dim l,t,c  
Dim i  
l=len(str)  
TStr=""  
t=0  
for i=1 to l  
c=asc(mid(str,i,1))  
If c<0 then c=c+65536  
If c>255 then  
t=t+2  
Else  
t=t+1  
End If  
TStr=TStr&(mid(str,i,1))  
If t>n Then  
TStr=TStr&"
"  
t=0  
End if  
next  
rowscode= TStr  
End If  
End Function  


16.截取字符串多余用省略号显示(支持中文) 

Function CutStr(byVal Str,byVal StrLen) 
  Dim l,t,c,i 
  l=Len(str) 
  t=0 
  For i=1 To l 
  c=AscW(Mid(str,i,1)) 
  If c<0 Or c>255 Then t=t+2 Else t=t+1 
  IF t>=StrLen Then 
  CutStr=left(Str,i)&"..." 
  Exit For 
  Else 
  CutStr=Str 
  End If 
  Next 
End Function 

 

17.注册帐号时密码随机生成的ASP代码 
ASP生成随机密码的两个函数: 
函数一 
 


makePassword(str) ’str 密码的位数 
函数二 
 


gen_key(str) ’str为密码位数  
这个函数还可以扩展。。如果你还要加上“大小写敏感区分大小写”特性的话,修改数组大小为char_array(50),然后在后面列出所有可能的小写字符。例如: 
char_array(36) = "a" 
char_array(37) = "b" 
...............类推 

18.获得ASP的中文日期字符串 
  
    我们通常需要在WEB页面上写上当前的日期,可能使用客户端script ,或者使用ASP。使用ASP的一个特点是,它产生的效果看起来是静态的页面,但实际上它是动态生成的。如果你希望用ASP显示一个中文的日期,则需要转化一下。下面是用来转化的函数及其调用实例。 
<<<< 函数实现 >>>> 
   


<<<< 调 用 举 例 >>>> 
 

19.判断输入域名是否正确的函数: 

dim c,words,word,i,wnum 
function IsValiddomin(word) 
IsValiddomin = true 
words = Split(word, ".") 
wnum=UBound(words) 
if words(0)="www" then 
IsValiddomin = IsValidword(words(1)) 
IsValiddomin = IsValidword2(words(2)) 
if words(wnum)="cn" then 
if wnum<>3 then 
IsValiddomin = false 
exit function 
end if 
else 
if wnum<>2 then 
IsValiddomin = false 
exit function 
end if 
end if 
else 
IsValiddomin = IsValidword(words(0)) 
IsValiddomin = IsValidword2(words(1)) 
if words(wnum)="cn" then 
if wnum<>2 then 
IsValiddomin = false 
exit function 
end if 
else 
if wnum<>1 then 
IsValiddomin = false 
exit function 
end if 
end if 
end if 
end function 

function IsValidword2(word) 
IsValidword2 = true 
IsValidword2 = IsValidword(word) 
if word<>"net" and word<>"com" and word<>"cc" and word<>"org" and word<>"info" and word<>"gov" then ’ 自己添加 
IsValidword2 = false 
exit function 
end if 
end function 

function IsValidword(word) 
IsValidword = true 

if Len(word) <= 0 then 
IsValidword = false 
exit function 
end if 
for i = 1 to Len(word) 
c = Lcase(Mid(word, i, 1)) 
if InStr("abcdefghijklmnopqrstuvwxyz-", c) <= 0 and not IsNumeric(c) then 
IsValidword = false 
exit function 
end if 
next 
end function 

if IsValiddomin("wrclub.net.cn") then 
response.write "right" 
else 
response.write "wrong" 
end if 


20.判断是否含有中文字符函数,函数主要用于设置密码,如ftp密码设置: 

function nothaveChinese(para) 
dim str 
nothaveChinese=true 
str=cstr(para) 
for i = 1 to Len(para) 
c=asc(mid(str,i,1)) 
if c<0 then  
nothaveChinese=false  
exit function 
end if 
next 
end function 

21.限制字符是否中文代码: 

function isChinese(para) 
on error resume next 
dim str 
dim i 
if isNUll(para) then  
isChinese=false 
exit function 
end if 
str=cstr(para) 
if trim(str)="" then 
isChinese=false 
exit function 
end if 
for i=1 to len(str) 
c=asc(mid(str,i,1)) 
if c>=0 then  
isChinese=false  
exit function 
end if 
next 
isChinese=true 
if err.number<>0 then err.clear 
end function 

 

22.判断Email是否正确函数: 

function IsValidEmail(email) 
dim names, name, i, c 
’Check for valid syntax in an email address. 
IsValidEmail = true 
names = Split(email, "@") 
if UBound(names) <> 1 then 
IsValidEmail = false 
exit function 
end if 
for each name in names 
if Len(name) <= 0 then 
IsValidEmail = false 
exit function 
end if 
for i = 1 to Len(name) 
c = Lcase(Mid(name, i, 1)) 
if InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 and not IsNumeric(c) then 
IsValidEmail = false 
exit function 
end if 
next 
if Left(name, 1) = "." or Right(name, 1) = "." then 
IsValidEmail = false 
exit function 
end if 
next 
if InStr(names(1), ".") <= 0 then 
IsValidEmail = false 
exit function 
end if 
i = Len(names(1)) - InStrRev(names(1), ".") 
if i <> 2 and i <> 3 then 
IsValidEmail = false 
exit function 
end if 
if InStr(email, "..") > 0 then 
IsValidEmail = false 
end if 
end function 

 

23.判断电话号码是否正确函数: 

function IsValidTel(para) 
on error resume next 
dim str 
dim l,i 
if isNUll(para) then  
IsValidTel=false 
exit function 
end if 
str=cstr(para) 
if len(trim(str))<7 then 
IsValidTel=false 
exit function 
end if 
l=len(str) 
for i=1 to l 
if not (mid(str,i,1)>="0" and mid(str,i,1)<="9" or mid(str,i,1)="-") then 
IsValidTel=false  
exit function 
end if 
next 
IsValidTel=true 
if err.number<>0 then err.clear 
end function 

 

24.判断文件名是否合法 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值