Date format validation using C# Regex

CsharpProgrammingServer Side Programming

Use the DateTime.TryParseExact method in C# for Date Format validation.

They method converts the specified string representation of a date and time to its DateTime equivalent. It checks whether the entered date format is correct or not.

Example

 Live Demo

using System;
using System.Globalization;

namespace Demo {
   class Program {
      static void Main(string[] args) {
         DateTime d;

         bool chValidity = DateTime.TryParseExact(
         "08/14/2018",
         "MM/dd/yyyy",
         CultureInfo.InvariantCulture,
         DateTimeStyles.None,
         out d);

         Console.WriteLine(chValidity);
      }
   }
}

Output

True
raja
Published on 21-Aug-2018 13:15:46
Advertisements