You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Thai Dang Vu <TV...@dhmh.state.md.us> on 2005/08/15 17:58:03 UTC
How to specify more than 1 datePattern in date validation?
Hi everybody,
If I want to validate a date field, I will put something like this in the validation.xml file
<field property="myDate" depends="date">
<arg0 key="Date field" resource="false"/>
<var>
<var-name>datePattern</var-name>
<var-value>MM/dd/yyyy</var-value>
</var>
</field>
So, if I want to enable 2 ways of entering a date (MM/dd/yyy and MM-dd-yyyy), how should I write in the validation.xml file?
Thanks for any help.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: How to specify more than 1 datePattern in date validation?
Posted by Laurie Harper <la...@holoweb.net>.
Thai Dang Vu wrote:
> If I want to validate a date field, I will put something like this in the validation.xml file
>
> <field property="myDate" depends="date">
> <arg0 key="Date field" resource="false"/>
> <var>
> <var-name>datePattern</var-name>
> <var-value>MM/dd/yyyy</var-value>
> </var>
> </field>
>
> So, if I want to enable 2 ways of entering a date (MM/dd/yyy and MM-dd-yyyy), how should I write in the validation.xml file?
The only two possibilities I can think of are to use the match validation
with a suitable regular expression, which will allow you to make sure the
date string is in the right format but can't easily check that it's really
a legal date, or write your own custom validation rule. The date validation
doesn't provide for specifying multiple patterns.
Actually, one other possibility: if you don't specify a pattern, Validator
will use SimpleDateFormat's default short date format rules, which might be
more flexible than you can express with a pattern; check the documentation
for SimpleDateFormat to see if that would meet your needs.
L.
--
Laurie Harper
Open Source advocate, Java geek: http://www.holoweb.net/laurie
Founder, Zotech Software: http://www.zotechsoftware.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org