Cześć,
Czy jest możliwe użycie funkcji regex.pattern w jednej linii tak aby spełnić co najmniej 3 z 4 warunków?
TRUE jest tylko wtedy kiedy 3 lub 4 warunki są spełnion z poniższych.
Tekst musi mieć:
Have lower characters
Have upper characters
Have a digit
Have a special character (Regex match [\W_])
moj kod na to wygląda tak:
Sub test()
Dim Text As String
Dim regex As Object
Dim counter As Byte
Dim Bool As Boolean
Text = "abc@123"
Set regex = CreateObject("VBScript.RegExp")
With regex
'upper letters
.Pattern = "[A-Z]+"
If .test(Text) = True Then
counter = counter + 1
End If
'lower letters
.Pattern = "[a-z]+"
If .test(Text) = True Then
counter = counter + 1
End If
'digits
.Pattern = "[0-9]+"
If .test(Text) = True Then
counter = counter + 1
End If
'special character
.Pattern = "[\W]+"
If .test(Text) = True Then
counter = counter + 1
End If
If counter >= 3 Then Bool = True
End With
Jak widać biorę każdy pattern oddzielnie i liczę warunki.
Regex ma mozliwosc grupowania warunkow ale nie umiem tego wprowadzić.
Proszę o pomoc,
Jacek