feurich Posted January 23, 2006 Posted January 23, 2006 Hi there, I am using th DateTime.Parse function to check if a datestring is valid. But when I type in "12", this is also validated as a valid datestring. the only datestrings that i want to be validated true are 1-1-2005, 01-9-2005, 31-12-2005, all others like 12-2005 or 07-05 for me are not valid dates. Could someone please help me on the way.. Thanks, Feurich Quote Trust the Universe
Cags Posted January 23, 2006 Posted January 23, 2006 I think using a regular expression might help then in that case, I'm not certain though as i've never used one. Quote Anybody looking for a graduate programmer (Midlands, England)?
Administrators PlausiblyDamp Posted January 23, 2006 Administrators Posted January 23, 2006 Could you post the exact code you used to parse the string "12" as it definately doesn't parse when I trie it here. Also DateTime.ParseExact may do what you need without requiring RegEx. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
feurich Posted January 23, 2006 Author Posted January 23, 2006 Typo :-( Sorry something went wrong with my typing. The problem accours when the string is like "-12-2005" this is seen as a valid date. [csharp] string AccumValue = "-12-2005" try { DateTime oDT = new DateTime(); oDT = DateTime.Parse(AccumValue); textBox2.Text = AccumValue; } catch(FormatException) { textBox2.Text = "01-10-1900"; } [/csharp] Quote Trust the Universe
feurich Posted January 25, 2006 Author Posted January 25, 2006 So any ideas Hi there, So from my point of view -12-2005 is not a valid date string. Or is -12-2005 a valid string date? Feurich Quote Trust the Universe
Administrators PlausiblyDamp Posted January 25, 2006 Administrators Posted January 25, 2006 If you have an exact format(s) you deem to be valid the DateTime.ParseExact is probably the easiest way. Out of curiosity is the date being entered via a windows / web application? If so you may find using a control like the DatetimePicker for a windows app or a validation control for a web app would prevent incorrect input being entered. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
feurich Posted January 25, 2006 Author Posted January 25, 2006 OCR Application The date is being read by an OCR engine and needs to be validated automaticaly. So there is no way of knowing what format will be read. If the scanned image is very dirty (speckles or noise) the OCR engine can read anything. So all the data needs to be checked. There are numeric flieds and VarChar and date fields. But the date fields are the easiest . Ok, thanks for the help. Feurich Quote Trust the Universe
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.