Created
July 17, 2024 09:24
-
-
Save xsnpdngv/03fe63aaf9bd765649425a35dd2cb3e8 to your computer and use it in GitHub Desktop.
Checks if a string value is a valid product number matching a regex
This file contains hidden or 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
Function IsValidValue(value As String, minLength As Integer, maxLength As Integer) As Boolean | |
Dim regex As Object | |
Set regex = CreateObject("VBScript.RegExp") | |
' Define the pattern to match the conditions: | |
' - Starts with one or more digits | |
' - Followed by zero or more letters | |
' - Only alphanumeric characters are allowed | |
regex.Pattern = "^\d+[a-zA-Z]*$" | |
regex.IgnoreCase = False | |
regex.Global = False | |
' Check if the value matches the pattern | |
If Not regex.Test(value) Then | |
IsValidValue = False | |
Exit Function | |
End If | |
' Check the length constraints | |
If Len(value) < minLength Or Len(value) > maxLength Then | |
IsValidValue = False | |
Exit Function | |
End If | |
' If all conditions are met, return True | |
IsValidValue = True | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment