Board index » delphi » How to validate date entered by user?

How to validate date entered by user?

Borland C++ builder Newbie simple qn:
I have TEdit->Text = '8 July 97'
Date entered by user on edit field. How do I validate the date entered
by the user. For example, if the user enters a wrong date '88 July
97',than I should be able to find out the wrong date.

 

Re:How to validate date entered by user?


Try defining a edit mask. Use TMaskEdit (or something like this, I don't
remember exactly).
--
Dmitry V. Girenko
KAMI-NT Newton Developers Division

name <al_...@candle.com> D?? ??? <33CF825C.5...@candle.com>...

Quote
> Borland C++ builder Newbie simple qn:
> I have TEdit->Text = '8 July 97'
> Date entered by user on edit field. How do I validate the date entered
> by the user. For example, if the user enters a wrong date '88 July
> 97',than I should be able to find out the wrong date.

Re:How to validate date entered by user?


Hi

OnExit event or on clicking the Ok button in the dialog you can take the text in
from the TEdit and make in a try - execept - end to transform it to a TDateTime.
If fails in the second part ( after execpt) you can go back or do what you
wan't. The TMaskEdit have few bugs an is not the best solution.

Good luck.

Keep in touch

Dany

Quote
?? ????? wrote:
> Try defining a edit mask. Use TMaskEdit (or something like this, I don't
> remember exactly).
> --
> Dmitry V. Girenko
> KAMI-NT Newton Developers Division

> name <al_...@candle.com> D?? ??? <33CF825C.5...@candle.com>...
> > Borland C++ builder Newbie simple qn:
> > I have TEdit->Text = '8 July 97'
> > Date entered by user on edit field. How do I validate the date entered
> > by the user. For example, if the user enters a wrong date '88 July
> > 97',than I should be able to find out the wrong date.

--
Szasz Daniel
Tel   : +972-4-8424580, +972-50-556392
Email : da...@israsrv.net.il
        dan...@mind.co.il
Country : Israel
Address : St. Sivtei Israel No. 26A/7
          Kiriat Haim 26275

Re:How to validate date entered by user?


Not only is MaskEdit buggy and annoying for anyone who isn't used to
mainframes, but it doesn't VALIDATE anything!  You need to do what Daniel
here mentions for validation, unless you want to validate by hand (eek).

Duff

Szasz Daniel <da...@israsrv.net.il> wrote in article
<33D11B4D.CCA5C...@israsrv.net.il>...

Quote
> Hi

> OnExit event or on clicking the Ok button in the dialog you can take the
text in
> from the TEdit and make in a try - execept - end to transform it to a
TDateTime.
> If fails in the second part ( after execpt) you can go back or do what
you
> wan't. The TMaskEdit have few bugs an is not the best solution.

> Good luck.

> Keep in touch

> Dany

> ?? ????? wrote:

> > Try defining a edit mask. Use TMaskEdit (or something like this, I
don't
> > remember exactly).
> > --
> > Dmitry V. Girenko
> > KAMI-NT Newton Developers Division

> > name <al_...@candle.com> D?? ???

<33CF825C.5...@candle.com>...

- Show quoted text -

Quote
> > > Borland C++ builder Newbie simple qn:
> > > I have TEdit->Text = '8 July 97'
> > > Date entered by user on edit field. How do I validate the date
entered
> > > by the user. For example, if the user enters a wrong date '88 July
> > > 97',than I should be able to find out the wrong date.

> --
> Szasz Daniel
> Tel   : +972-4-8424580, +972-50-556392
> Email : da...@israsrv.net.il
>         dan...@mind.co.il
> Country : Israel
> Address : St. Sivtei Israel No. 26A/7
>           Kiriat Haim 26275

Re:How to validate date entered by user?


If you are using a TDateField, date validation is performed automatically,
ie. if the entered date is not a valid date, an exception is raised.
However if you wish to restrict the entry to a date range, such as
01/01/1997 to 12/31/1997, then you want to use the OnValidate event of the
TDateField:

   if (dtField.AsDateTime < StrToDate('01/01/1997')) or (dtField.AsDateTime

Quote
> StrToDate('12/31/1997') then

      raise Exception.Create('Date out of range');

I notice you're using C++ Builder...the above code is Delphi, but I'm sure
you (or someone here) can handle the conversion.  I'm still waiting to
receive my copy of C++ Builder for attending this year's Borland
Conference...

Mike Duff <d...@mcs.com> wrote in article
<01bc98ea$f199f7e0$6e2003c7@phaeton>...

Quote
> Not only is MaskEdit buggy and annoying for anyone who isn't used to
> mainframes, but it doesn't VALIDATE anything!  You need to do what Daniel
> here mentions for validation, unless you want to validate by hand (eek).

> Duff

> Szasz Daniel <da...@israsrv.net.il> wrote in article
> <33D11B4D.CCA5C...@israsrv.net.il>...
> > Hi

> > OnExit event or on clicking the Ok button in the dialog you can take
the
> text in
> > from the TEdit and make in a try - execept - end to transform it to a
> TDateTime.
> > If fails in the second part ( after execpt) you can go back or do what
> you
> > wan't. The TMaskEdit have few bugs an is not the best solution.

> > Good luck.

> > Keep in touch

> > Dany

> > ?? ????? wrote:

> > > Try defining a edit mask. Use TMaskEdit (or something like this, I
> don't
> > > remember exactly).
> > > --
> > > Dmitry V. Girenko
> > > KAMI-NT Newton Developers Division

> > > name <al_...@candle.com> D?? ???
> <33CF825C.5...@candle.com>...
> > > > Borland C++ builder Newbie simple qn:
> > > > I have TEdit->Text = '8 July 97'
> > > > Date entered by user on edit field. How do I validate the date
> entered
> > > > by the user. For example, if the user enters a wrong date '88 July
> > > > 97',than I should be able to find out the wrong date.

> > --
> > Szasz Daniel
> > Tel   : +972-4-8424580, +972-50-556392
> > Email : da...@israsrv.net.il
> >         dan...@mind.co.il
> > Country : Israel
> > Address : St. Sivtei Israel No. 26A/7
> >           Kiriat Haim 26275

Other Threads