Hi @Simflex ,
Uses DateTime.TryParseExact
with "dd/MM/yyyy"
to check if the date is valid (e.g., rejects 31/04/2024
or 29/02/2025
as 2025 is not a leap year).
Function IsValidInput(ByVal input As String) As Boolean
Dim pattern As String = "^[A-Z]{2}(\d{2})(\d{2})(\d{4})$"
Dim match As Match = Regex.Match(input, pattern)
If match.Success Then
Dim day As Integer = Integer.Parse(match.Groups(1).Value)
Dim month As Integer = Integer.Parse(match.Groups(2).Value)
Dim year As Integer = Integer.Parse(match.Groups(3).Value)
' Validate the date
Dim dateString As String = $"{day:D2}/{month:D2}/{year:D4}"
Dim parsedDate As DateTime
If DateTime.TryParseExact(dateString, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, parsedDate) Then
Return True
End If
End If
Return False
End Function
Best Regards.
Jiachen Li
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.