LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
版主

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

tercel
2011年4月6日 22:40 本文热度 2393
'----------------------------------------------------------------------------------------------------
' 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

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

IsValidNumber =  IsNumeric(sInput)

End Function

'----------------------------------------------------------------------------------------------------
' Function Name : IsValidLetters
' Function Desc : 判断输入是否是一个由 A-Z / a-z 组成的字符串
'----------------------------------------------------------------------------------------------------
Public Function IsValidLetters(sInput)

Dim oRegExp

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

'设置模式
oRegExp.Pattern = "^[a-zA-Z]+$"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

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

Set oRegExp = Nothing

End Function

'----------------------------------------------------------------------------------------------------
' Function Name : IsValidDigits
' Function Desc : 判断输入是否是一个由 0-9 组成的数字
'----------------------------------------------------------------------------------------------------
Public Function IsValidDigits(sInput)

Dim oRegExp

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

'设置模式
oRegExp.Pattern = "^[1-9][0-9]*$"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

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

Set oRegExp = Nothing

End Function

'----------------------------------------------------------------------------------------------------
' Function Name : IsValidAlphanumeric
' Function Desc : 判断输入是否是一个由 0-9 / A-Z / a-z 组成的字符串
'----------------------------------------------------------------------------------------------------
Public Function IsValidAlphanumeric(sInput)

Dim oRegExp

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

'设置模式
oRegExp.Pattern = "^[a-zA-Z0-9]+$"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

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

Set oRegExp = Nothing

End Function

'----------------------------------------------------------------------------------------------------
' Function Name : IsValidString
' Function Desc : 判断输入是否是一个由 0-9 / A-Z / a-z / . / _ 组成的字符串
'----------------------------------------------------------------------------------------------------
Public Function IsValidString(sInput)

Dim oRegExp

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

'设置模式
oRegExp.Pattern = "^[a-zA-Z0-9\s.\-_]+$"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

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

Set oRegExp = Nothing

End Function

'----------------------------------------------------------------------------------------------------
' Function Name : IsValidPostalcode
' Function Desc : 判断输入是否是一个有效的邮政编码
'----------------------------------------------------------------------------------------------------
Public Function IsValidPostalcode(sInput)

Dim oRegExp

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

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

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

Set oRegExp = Nothing

End Function

'----------------------------------------------------------------------------------------------------
' Function Name : IsValidPhoneNo
' Function Desc : 判断输入是否是一个有效的电话号码
'----------------------------------------------------------------------------------------------------
Public Function IsValidPhoneNo(sInput)

Dim oRegExp

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

'设置模式
oRegExp.Pattern = "(^0\d{2,3}\-[1-9]\d{2,7}$)|(^[1-9]\d{2,7}$)|(^\(0[1-9]{2,3}\)[1-9]\d{2,7}$)"
'设置是否区分字符大小写
oRegExp.IgnoreCase = True
'设置全局可用性
oRegExp.Global = True

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

Set oRegExp = Nothing

End Function

'----------------------------------------------------------------------------------------------------
' Function Name : IsValidMobileNo
' Function Desc : 判断输入是否是一个有效的手机号码
'----------------------------------------------------------------------------------------------------
Public Function IsValidMobileNo(sInput)

Dim oRegExp

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

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

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

Set oRegExp = Nothing

End Function
 

该文章在 2011/4/6 22:40:52 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved