Created
May 31, 2012 06:58
-
-
Save hiscaler/2841569 to your computer and use it in GitHub Desktop.
ASP ValidatorHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
'##################### | |
' 数据验证 | |
' author: hiscaler | |
' create date: 2012-5-29 | |
'##################### | |
Class Class_ValidatorHelper | |
Public Function isRequired(ByVal value) | |
If (UtilHelper.checkNull(value)) Then | |
isRequired = False | |
Else | |
isRequired = True | |
End If | |
End Function | |
Public Function isDate(ByVal value) | |
If (UtilHelper.checkNull(value)) Then | |
isDate = False | |
Else | |
If (IsDate(value)) Then | |
isDate = True | |
Else | |
isDate = False | |
End If | |
End If | |
End Function | |
Public Function isTel(ByVal value) | |
isTel = RegPattern("^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$", value) | |
End Function | |
Public Function isZipcode(ByVal value) | |
isZipcode = RegPattern("^[1-9]\d{5}$", value) | |
End Function | |
Public Function isEmail(ByVal value) | |
isEmail = RegPattern("^[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$", value) | |
End Function | |
Public Function isURL(ByVal value) | |
isURL = RegPattern("^(http[s]?|ftp):\/\/[^\/\.]+?\..+\w$", value) | |
End Function | |
Public Function stringRange(ByVal value, ByVal min, ByVal max) | |
If (min = 0) Then | |
stringRange = True | |
Else | |
Dim l:l = StringHelper.strLength(value) | |
If (l >= min AND l <= max) Then | |
stringRange = True | |
Else | |
stringRange = False | |
End If | |
End If | |
End Function | |
Public Function numberRange(ByVal value, ByVal min, ByVal max) | |
If (isNumber(value)) Then | |
If (value >= min AND value <= max) Then | |
numberRange = True | |
Else | |
numberRange = False | |
End If | |
Else | |
numberRange = False | |
End If | |
End Function | |
Public Function isMobilephone(ByVal value) | |
isMobilephone = RegPattern("^((\(\d{3}\))|(\d{3}\-))?13|15\d{9}$", value) | |
End Function | |
Public Function isNumber(ByVal value) | |
isNumber = RegPattern("^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$", value) | |
End Function | |
Public Function isInteger(ByVal value) | |
isInteger = RegPattern("^\s*[+-]?\d+\s*$", value) | |
End Function | |
Public Function isEnglish(ByVal value) | |
isEnglish = RegPattern("^[A-Za-z]+$", value) | |
End Function | |
Public Function isChinese(ByVal value) | |
isChinese = RegPattern("^[\u0391-\uFFE5]+$", value) | |
End Function | |
Public Function isQQ(ByVal value) | |
isQQ = RegPattern("^[1-9]\d{4,9}$", value) | |
End Function | |
Public Function isDomain(ByVal value) | |
isDomain = RegPattern("^[A-Za-z0-9\-]+\.([A-Za-z]{2,4}|[A-Za-z]{2,4}\.[A-Za-z]{2})$", value) | |
End Function | |
Public Function isIP(ByVal value) | |
isIP = RegPattern("^(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])$", value) | |
End Function | |
' 根据扩展名判断是否为图片文件 | |
Public Function isImageByExt(ByVal value) | |
If (ArrayHelper.inArray(FileHelper.getFileExt(value), Array("jpg", "jpeg", "png", "bmp", "gif"))) Then | |
isImageByExt = True | |
Else | |
isImageByExt = False | |
End If | |
End Function | |
' 正则比配 | |
Private Function RegPattern(ByVal pattern, ByVal value) | |
RegPattern = false | |
Dim regEx, Match, Matches '建立变量。 | |
Set regEx = New RegExp '建立正则表达式。 | |
regEx.Pattern = pattern'设置模式。 | |
regEx.IgnoreCase = True '设置是否区分字符大小写。 | |
regEx.Global = True '设置全局可用性。 | |
If regEx.Test(value) Then | |
RegPattern = true | |
End if | |
End Function | |
End Class | |
Dim ValidatorHelper | |
set ValidatorHelper = new Class_ValidatorHelper | |
%> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment