VBScript detection functions that are frequently used

Source: Internet
Author: User

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: Length
'Function Desc: returns the actual length of a string. One Chinese character is counted as two lengths.
'Timeout '----------------------------------------------------------------------------------------------------
Public Function length (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "[^ \ x00-\ xFF]"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Length = Len (oregexp. Replace (sinput ,"**"))

Set oregexp = nothing

End Function

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

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ \ D {4}-\ D {2}-\ D {2} $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
If oregexp. Test (sinput) then
Isvaliddate = isdate (sinput)
Else
Isvaliddate = false
End if

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvalidtime
'Function Desc: determines whether the input is in a valid time format-"HH: mm: SS"
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvalidtime (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ \ D {2 }:\ d {2 }:\ d {2} $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
If oregexp. Test (sinput) then
Isvalidtime = isdate (sinput)
Else
Isvalidtime = false
End if

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvalidemail
'Function Desc: determines whether the input is a valid email.
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvalidemail (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ \ W + (-\ W +) | (\. \ W) * \ @ [A-Za-z0-9] + ((\. |-) [A-Za-z0-9] + )*\. [A-Za-z0-9] + $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvalidemail = oregexp. Test (sinput)

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvaliddatetime
'Function Desc: determines whether the input is in a valid long date format-"YYYY-MM-DD hh: mm: SS"
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvaliddatetime (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ \ D {4}-\ D {2}-\ D {2} \ D {2 }:\ d {2 }:\ d {2} $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
If oregexp. Test (sinput) then
Isvaliddatetime = isdate (sinput)
Else
Isvaliddatetime = false
End if

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvalidinteger
'Function Desc: determines whether the input is an integer.
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvalidinteger (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ (-| \ + )? \ D + $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvalidinteger = oregexp. Test (sinput)

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvalidpositiveinteger
'Function Desc: determines whether the input is a positive integer.
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvalidpositiveinteger (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ (\ + )? \ D + $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvalidpositiveinteger = oregexp. Test (sinput)

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvalidnegativeinteger
'Function Desc: determines whether the input is a negative integer.
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvalidnegativeinteger (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^-\ D + $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvalidnegativeinteger = oregexp. Test (sinput)

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvalidnumber
'Function Desc: determines whether the input is a number.
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvalidnumber (sinput)

Isvalidnumber = isnumeric (sinput)

End Function

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

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ [A-Za-Z] + $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvalidletters = oregexp. Test (sinput)

Set oregexp = nothing

End Function

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

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ [1-9] [0-9] * $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvaliddigits = oregexp. Test (sinput)

Set oregexp = nothing

End Function

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

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ [a-zA-Z0-9] + $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvalidalphanumeric = oregexp. Test (sinput)

Set oregexp = nothing

End Function

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

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ [a-zA-Z0-9 \ s. \-_] + $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvalidstring = oregexp. Test (sinput)

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvalidpostalcode
'Function Desc: determines whether the input is a valid zip code.
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvalidpostalcode (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ \ D {6} $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvalidpostalcode = oregexp. Test (sinput)

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvalidphoneno
'Function Desc: determines whether the input is a valid phone number.
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvalidphoneno (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting 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} $ )"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the search
Isvalidphoneno = oregexp. Test (sinput)

Set oregexp = nothing

End Function

'Timeout '----------------------------------------------------------------------------------------------------
'Function name: isvalid=eno
'Function Desc: determines whether the input is a valid mobile phone number.
'Timeout '----------------------------------------------------------------------------------------------------
Public Function isvalidmobileno (sinput)

Dim oregexp

'Create a regular expression
Set oregexp = new Regexp

'Setting Mode
Oregexp. pattern = "^ 0? 13 \ D {9} $"
'Specifies whether to distinguish between uppercase and lowercase characters.
Oregexp. ignorecase = true
'Set global availability
Oregexp. Global = true

'Execute the 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.