Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Trust the Universe
Posted
I think using a regular expression might help then in that case, I'm not certain though as i've never used one.
Anybody looking for a graduate programmer (Midlands, England)?
Posted

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]

Trust the Universe
Posted

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

Trust the Universe
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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

Trust the Universe

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...