struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Gordon <Adam.Gor...@readytalk.com>
Subject RE: Accepting multiple date masks with the "date" validator
Date Thu, 03 Aug 2006 15:16:49 GMT
IIOC, the only way you can do this with the stock validator is to use "mask"
rather than "date" as the validator.  Then, you can use a regex to dictate
your mask.  I'll warn you though, if you use a regular expression it's going
to be VERY long because it will also need to validate that the date entered
is valid.  Additionally, the stock date validator accepts dates like 30 FEB
YYYY and just rolls it to the appropriate March date.  Here's the REGEX we
use (note that the regex is all on one line with no spaces:

<var>
  <var-name>mask</var-name>
 
<var-value>^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(2
9|30)|(0?[13578]|1[02])/31)/(20)((0[6-9])|(10))|0?2/29/((20)(0[48])))$</var-
value>
</var>

Alternatively, you can override the validate method in your ValidatorForm
and do it yourself - which given your requirements, sounds like the easier
of the two options.

-Adam


-----Original Message-----
From: Scott Van Wart [mailto:scott@indosoft.com] 
Sent: Wednesday, 02 August 2006 14:59
To: user@struts.apache.org
Subject: Accepting multiple date masks with the "date" validator

I have a requirement in my project that I be able to accept two 
different date masks.  One with slashes (thus, 10 characters) and one 
without (8 digits).  Is there any way to do this with the stock date 
validator, or do I need to roll my own wrapper?

Thanks,
  Scott

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message