日期:2010-07-07  浏览次数:20866 次

'----------------------------------------------------------
' 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 : 判断输入是否是一个正整数
'-----------------------------------------------------------
Pu