validating a date
-
hi i am trying to validate a string that contains a date using DateTime.parse function but this function accepts for example the date "31-feb-2007" !! how can i validate the date to be valid not just the format . thanks
-
hi i am trying to validate a string that contains a date using DateTime.parse function but this function accepts for example the date "31-feb-2007" !! how can i validate the date to be valid not just the format . thanks
hi, i think u can use a regularexpression along with the parser....its up to u arun
-
hi i am trying to validate a string that contains a date using DateTime.parse function but this function accepts for example the date "31-feb-2007" !! how can i validate the date to be valid not just the format . thanks
-
hi i am trying to validate a string that contains a date using DateTime.parse function but this function accepts for example the date "31-feb-2007" !! how can i validate the date to be valid not just the format . thanks
if you are using VB.NET there is a function - IsDate() which can be used to validate the date. you could also use compare or range validators, depending on your choice and use, to check the data type. but i don't think these will validate if the date string contains alphabets as expressed in your example. but if you are using C#.NET, i think try-catch block (as someone already mentioned) will do the job.:) hope this helps regards :)
-
hi i am trying to validate a string that contains a date using DateTime.parse function but this function accepts for example the date "31-feb-2007" !! how can i validate the date to be valid not just the format . thanks
thank u all the try/catch block works fine
-
hi i am trying to validate a string that contains a date using DateTime.parse function but this function accepts for example the date "31-feb-2007" !! how can i validate the date to be valid not just the format . thanks
try this
bool validatedate(string datestr) { try { System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US"); DateTime tmpDate= DateTime.ParseExact(date, "dd-MMM-yyyy", culture); return true; } catch(Exception ex) { return false; } }
Regards R.Arockiapathinathan
-
hi i am trying to validate a string that contains a date using DateTime.parse function but this function accepts for example the date "31-feb-2007" !! how can i validate the date to be valid not just the format . thanks
Instead of using exception handling as logic as some people have suggested try something like this:
public bool ValidateDate(string date)
{
DateTime temp;
return DateTime.TryParse(date, out temp);
}