date formats
-
private static void SetSelected(string Date) { string[] ResultList; Regex DateSplitter = new Regex("^\\d{4,4}\\/\\d{1,2}\\/\\d{1,2}$"); if(DateSplitter.IsMatch(Date)) { char divider = '/'; ResultList = Date.Split(divider); int SelectedYear = Int32.Parse(ResultList[0]); int SelectedMonth = Int32.Parse(ResultList[1]); int SelectedDay = Int32.Parse(ResultList[2]); int CompareDay=0; if(SelectedMonth<=12 ) { CompareDay=DateTime.DaysInMonth(SelectedYear,SelectedMonth); } else { Console.WriteLine("Invalid Date"); return ; } if(SelectedDay >CompareDay) { Console.WriteLine("Invalid Date"); return ; } else if(SelectedYear>=2100 || SelectedYear <= 1900 ) { Console.WriteLine("Invalid Date"); return ; } else { Console.WriteLine("Valid"); } } else { Console.WriteLine("InValid Date"); } }