Test 方法

檢查指定的字串是否符合正規表示式樣式。Test 方法會傳回布林值 (True 或 False)。如果字串符合樣式,則傳回 True;如果不符合,則傳回 False。

語法RegExpObject.Test(string)

引數: - string:您要用來測試正規表示式樣式的字串。

範例:

Dim regEx, str, result

' Create a new RegExp object
Set regEx = CreateObject("VBScript.RegExp")

' Set the pattern for matching email addresses
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"

' Test if the string is a valid email
str = "example@example.com"
result = regEx.Test(str)
If result Then
    'Logic for Valid email
Else
    'Logic for Invalid email
End If