手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp编程>列表

一些经常会用到的vbscript检测函数

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
'----------------------------------------------------------
' Function Name : Length
' Function Desc : 返回字符串的实际长度, 一个汉字算2个长度
'---------------------------------------------------------
Public Function Length(sInput)

Dim oRegExp

'建立正则表达式
Set oRegExp = New RegExp

'设置模式
oRegExp.Pattern = "[^\x00-\xff]"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

'执行搜索
Length = Len(oRegExp.Replace(sInput, "**"))

Set oRegExp = Nothing

End Function

'-----------------------------------------------------------------
' Function Name : IsValidDate
' Function Desc : 判断输入是否是有效的短日期格式 - "YYYY-MM-DD"
'----------------------------------------------------------------
Public Function IsValidDate(sInput)

Dim oRegExp

'建立正则表达式
Set oRegExp = New RegExp

'设置模式
oRegExp.Pattern = "^\d{4}-\d{2}-\d{2}$"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

'执行搜索
If oRegExp.Test(sInput) Then
IsValidDate = IsDate(sInput)
Else
IsValidDate = False
End If

Set oRegExp = Nothing

End Function

'-------------------------------------------------------------
' Function Name : IsValidTime
' Function Desc : 判断输入是否是有效的时间格式 - "HH:MM:SS"
'--------------------------------------------------------------
Public Function IsValidTime(sInput)

Dim oRegExp

'建立正则表达式
Set oRegExp = New RegExp

'设置模式
oRegExp.Pattern = "^\d{2}:\d{2}:\d{2}$"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

'执行搜索
If oRegExp.Test(sInput) Then
IsValidTime = IsDate(sInput)
Else
IsValidTime = False
End If

Set oRegExp = Nothing

End Function

'---------------------------------------------------------
' Function Name : IsValidEmail
' Function Desc : 判断输入是否是有效的电子邮件
'---------------------------------------------------------
Public Function IsValidEmail(sInput)

Dim oRegExp

'建立正则表达式
Set oRegExp = New RegExp

'设置模式
oRegExp.Pattern = "^\w ((-\w )|(\.\w))*\@[A-Za-z0-9] ((\.|-)[A-Za-z0-9] )*\.[A-Za-z0-9] $"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

'执行搜索
IsValidEmail = oRegExp.Test(sInput)

Set oRegExp = Nothing

End Function

'------------------------------------------------------------
' Function Name : IsValidDatetime
' Function Desc : 判断输入是否是有效的长日期格式 - "YYYY-MM-DD HH:MM:SS"
'------------------------------------------------------------
Public Function IsValidDatetime(sInput)

Dim oRegExp

'建立正则表达式
Set oRegExp = New RegExp

'设置模式
oRegExp.Pattern = "^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

'执行搜索
If oRegExp.Test(sInput) Then
IsValidDatetime = IsDate(sInput)
Else
IsValidDatetime = False
End If

Set oRegExp = Nothing

End Function

'----------------------------------------------------------------
' Function Name : IsValidInteger
' Function Desc : 判断输入是否是一个整数
'----------------------------------------------------------------
Public Function IsValidInteger(sInput)

Dim oRegExp

'建立正则表达式
Set oRegExp = New RegExp

'设置模式
oRegExp.Pattern = "^(-|\ )?\d $"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

'执行搜索
IsValidInteger = oRegExp.Test(sInput)

Set oRegExp = Nothing

End Function

'-------------------------------------------------------------
' Function Name : IsValidPositiveInteger
' Function Desc : 判断输入是否是一个正整数
'-----------------------------------------------------------
Public Function IsValidPositiveInteger(sInput)

Dim oRegExp

'建立正则表达式
Set oRegExp = New RegExp

'设置模式
oRegExp.Pattern = "^(\ )?\d $"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

'执行搜索
IsValidPositiveInteger = oRegExp.Test(sInput)

Set oRegExp = Nothing

End Function

'-------------------------------------------------------------
' Function Name : IsValidNegativeInteger
' Function Desc : 判断输入是否是一个负整数
'-------------------------------------------------------------
Public Function IsValidNegativeInteger(sInput)

Dim oRegExp

'建立正则表达式
Set oRegExp = New RegExp

'设置模式
oRegExp.Pattern = "^-\d $"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

'执行搜索
IsValidNegativeInteger = oRegExp.Test(sInput)

Set oRegExp = Nothing

End Function

'-------------------------------------------------------

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!