Please help me with a regular expression to validate the following format
dd/mm
This is for validating a Birthday field and the year is not required.
Thanks
bool foundMatch = false;
foundMatch = Regex.IsMatch(SubjectString,
@"^(?:
(?:[12][0-9]|0?[1-9])/(?:0?2|Feb(?:ruary)?)
|
(?:30|[12][0-9]|0?[1-9])/
(?:
(?:0?[469]|11)
|
Apr(?:il)?|June?|Sep(?:tember)?|Nov(?:ember)?
)
|
(?:3[01]|[12][0-9]|0?[1-9])/
(?:
(?:0?[13578]|1[02])
|
Jan(?:uary)?|Mar(?:ch)?|May|July?|Aug(?:ust)?|Oct(?:ober)?|Dec(?:ember)?
)
)$",
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
will match valid days/months. It will always match Feb 29 since it doesn't know the year.
By the way, I made this regex using RegexMagic (much too tedious to do this manually - another sign that this is rather a job for a date/time parser).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With