Skip to content

Instantly share code, notes, and snippets.

@xsnpdngv
Created July 17, 2024 09:24
Show Gist options
  • Save xsnpdngv/03fe63aaf9bd765649425a35dd2cb3e8 to your computer and use it in GitHub Desktop.
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
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