[Zope] Are regular expression integrated in DTML in some way?

Andrew Williams ajwms@hotmail.com
Fri, 13 Apr 2001 12:04:33 -0400


Tony:

> It's unbelievable! I'm losing my MiNd!

hehehe... I know what your saying...


> (And no I'm not selling furniture or used cars 8)
>
> I've spent the last 2 hours trying to find the answer to what I thought
was
> a simple question.
>
> What is the simplest way to validate a form input date in the syntax of
> MM/DD/YYYY?

Does it matter if it is in MM/DD/YYYY?  As long as it is a valid date, you
can convert it to a DateTime object and display it however you want to.  See
code sample below...

>
> I was thinking a simple regular expression would be ideal but I found no
> reference suggesting that regexp's are supported in DTML and you cannot
> import the regexp object in a Python script without creating a custom
> product/script and that seems too convoluted so that leads me to believe
> that there must be another way that I just haven't found yet.
>
> If you have a suggestion please let me know

Try this code sample:

---------------------------------------------------------
<dtml-let gooddateSTR="'02/04/2001'"
          baddateSTR="'02/2a/2001'">

  <dtml-try>
    <dtml-call
expr="REQUEST.set('gooddateDATETIME',_.DateTime(gooddateSTR))">
  <dtml-except>
    This date is invalid: <dtml-var gooddateSTR>
  <dtml-else>
    This date is good: <dtml-var gooddateDATETIME fmt="%m/%d/%Y">
  </dtml-try>

<BR><BR>

  <dtml-try>
    <dtml-call expr="REQUEST.set('baddateDATETIME',_.DateTime(baddateSTR))">
  <dtml-except>
    This date is invalid: <dtml-var baddateSTR>
  <dtml-else>
    This date is good: <dtml-var baddateDATETIME fmt="%m/%d/%Y">
  </dtml-try>

</dtml-let>
-------------------------------------------------------

HTW,

Andrew Williams