Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validate a date
Message
De
15/07/2006 04:08:18
 
 
À
14/07/2006 15:34:12
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
ASP.NET
Divers
Thread ID:
01136539
Message ID:
01136631
Vues:
29
Hi,

>I have a ASP.Net webform that contains a textbox where a user should enter a date in mm/dd/yy format.
>
>How can I validate that the user enter a good date?

Take a look at : http://www.codeguru.com/csharp/.net/net_general/netframeworkclasses/article.php/c7547/

Jist of it is:
static bool ValidateDate(String date, String format)
{
   try
   {
      System.Globalization.DateTimeFormatInfo dtfi = new
             System.Globalization.DateTimeFormatInfo();
      dtfi.ShortDatePattern = format;
      DateTime dt = DateTime.ParseExact(date, "d", dtfi);
   }
   catch(Exception)
   {
      return false;
   }
   return true;
}
HTH,
Viv
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform