Some of the VBScript detection functions that are often used

Source: Internet
Author: User
Tags date format functions integer valid
vbscript| function '----------------------------------------------------------
' Function name:length
' Function Desc: Returns the actual length of the string, one Chinese character counts 2 lengths
'---------------------------------------------------------
Public Function Length (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "[^\x00-\xff]"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Length = Len (Oregexp.replace (Sinput, "* *"))

Set Oregexp = Nothing

End Function

'-----------------------------------------------------------------
' Function name:isvaliddate
' Function Desc: Determines whether the input is a valid short date format-"YYYY-MM-DD"
'----------------------------------------------------------------
Public Function isvaliddate (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^\d{4}-\d{2}-\d{2}$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
If oregexp.test (sinput) Then
Isvaliddate = IsDate (sinput)
Else
Isvaliddate = False
End If

Set Oregexp = Nothing

End Function

'-------------------------------------------------------------
' Function name:isvalidtime
' Function Desc: Determines whether the input is a valid time format-"HH:MM:SS"
'--------------------------------------------------------------
Public Function isvalidtime (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^\d{2}:\d{2}:\d{2}$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
If oregexp.test (sinput) Then
Isvalidtime = IsDate (sinput)
Else
Isvalidtime = False
End If

Set Oregexp = Nothing

End Function

'---------------------------------------------------------
' Function Name:isvalidemail
' Function Desc: Determines whether the input is a valid e-mail message
'---------------------------------------------------------
Public Function IsValidEmail (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^\w+ (-\w+) | ( \.\w)) *\@[a-za-z0-9]+ (\.| -) [a-za-z0-9]+) *\. [a-za-z0-9]+$]
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
IsValidEmail = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'------------------------------------------------------------
' Function name:isvaliddatetime
' Function Desc: Determines whether the input is a valid long date format-"Yyyy-mm-dd HH:MM:SS"
'------------------------------------------------------------
Public Function isvaliddatetime (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
If oregexp.test (sinput) Then
Isvaliddatetime = IsDate (sinput)
Else
Isvaliddatetime = False
End If

Set Oregexp = Nothing

End Function

'----------------------------------------------------------------
' Function Name:isvalidinteger
' Function Desc: Determines whether the input is an integer
'----------------------------------------------------------------
Public Function Isvalidinteger (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^ (-|\+)? \d+$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Isvalidinteger = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'-------------------------------------------------------------
' Function Name:isvalidpositiveinteger
' Function Desc: Determines whether the input is a positive integer
'-----------------------------------------------------------
Public Function Isvalidpositiveinteger (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^ (\+)? \d+$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Isvalidpositiveinteger = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'-------------------------------------------------------------
' Function Name:isvalidnegativeinteger
' Function Desc: Determines whether the input is a negative integer
'-------------------------------------------------------------
Public Function Isvalidnegativeinteger (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^-\d+$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Isvalidnegativeinteger = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'-------------------------------------------------------
' Function Name:isvalidnumber
' Function Desc: Determines whether the input is a number
'------------------------------------------------------
Public Function Isvalidnumber (sinput)

Isvalidnumber = IsNumeric (sinput)

End Function

'----------------------------------------------------------
' Function name:isvalidletters
' Function Desc: Determines whether the input is a A-z/A-Z string
'----------------------------------------------------------
Public Function isvalidletters (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^[a-za-z]+$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Isvalidletters = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'----------------------------------------------------------
' Function name:isvaliddigits
' Function Desc: Determines whether the input is a number consisting of 0-9
'----------------------------------------------------------
Public Function isvaliddigits (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^[1-9][0-9]*$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Isvaliddigits = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'--------------------------------------------------------------
' Function name:isvalidalphanumeric
' Function Desc: Determines whether the input is a string composed of 0-9/A-z/A-Z
'---------------------------------------------------------------
Public Function isvalidalphanumeric (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^[a-za-z0-9]+$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Isvalidalphanumeric = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'-------------------------------------------------------------
' Function name:isvalidstring
' Function Desc: Determines whether the input is a by 0-9/A-z/A-z/. /_ A string consisting of
'-------------------------------------------------------------
Public Function isvalidstring (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^[a-za-z0-9\s.\-_]+$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
isvalidstring = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'-----------------------------------------------------------------
' Function Name:isvalidpostalcode
' Function Desc: Determines whether the input is a valid ZIP code
'----------------------------------------------------------------
Public Function Isvalidpostalcode (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^\d{6}$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Isvalidpostalcode = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'-------------------------------------------------------------------
' Function Name:isvalidphoneno
' Function Desc: Determines whether the input is a valid phone number
'-------------------------------------------------------------------
Public Function Isvalidphoneno (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
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}$) "
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Isvalidphoneno = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

'--------------------------------------------------------------------
' Function Name:isvalidmobileno
' Function Desc: Determine if the input is a valid cell phone number
'---------------------------------------------------------------------
Public Function Isvalidmobileno (sinput)

Dim Oregexp

' Establish regular expressions
Set oregexp = New RegExp

' Set mode
Oregexp.pattern = "^0?13\d{9}$"
' Sets whether to differentiate character case
Oregexp.ignorecase = True
' Set global availability
Oregexp.global = True

' Perform a search
Isvalidmobileno = Oregexp.test (sinput)

Set Oregexp = Nothing

End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.