Trying to write a regex expression in C# that accepts any/all of the following:
- 02/01/1968
- 2/01/1968
- 2/1/1968
(This question is somewhat different then other similar questions in that this is to be a single word, in mm/dd/yyyy format. Only the pattern is needed without verification as to its possibility. i.e., 99/99/9999 is o.k.)
I am getting nowhere fast. Here is as far as I've gotten (which only recognizes 02/01/1968):
Regex regex = new Regex(@"^\d{2}/\d{2}/\d{4}$",RegexOptions.IgnorePatternWhitespace);
Match x = regex.Match(birthdate);
if (x.Success == false) return;
Thanks for any help. (An explanation with the regex would be most appreciated).
@"^\d{1,2}/\d{1,2}/\d{4}$"
DateTime.TryParseExact
.true
andfalse
. Changeif (x.Success == false) return;
toif (!x.Success) return;