I need a regex for the following pattern:
- Total of 4 characters (numeric, alpha, numeric, numeric).
- first character must be a number(0-9)
- second character must be a number(A-M i should not come) -> this refer to month jan to dec
-third and fourth characters must be a number(0-9) -> Date
Examples:
- 3K01 is valid
- 3K40 is invalid
- 5I01 is invalid -> A-M
- 1A01 is valid
Dim validateLot As String = "/^((0?[1-9]|1[012])M|(0?[1-9]|[12][0-9]|3[01])D)$/"
Dim r As New Regex(validateLot)
If (r.IsMatch(txtCarton0.Text)) Then
Else
End If
2
Answers
Is this what you need
https://regex101.com/r/4Y9fcU/1
So, there are 4 characters, numeric, alpha, numeric, numeric.
They represent as follows:
d
or[0-9]
[A-HJ-M]
Calendar Date (01-31)
So, third & fourth character matching regex:
(([0][1-9])|([1-2][0-9])|([3][0-1]))
Therefore your regex should be:
Test regex: https://regex101.com/r/7AImf2/1
Thank You