<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Beware using DateFormat for input&#160;validation</title>
	<atom:link href="http://www.magpiebrain.com/blog/2004/05/17/beware-using-dateformat-for-input-validation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.magpiebrain.com/blog/2004/05/17/beware-using-dateformat-for-input-validation/</link>
	<description>Sam Newman's blog</description>
	<pubDate>Wed, 15 Oct 2008 19:55:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Hale</title>
		<link>http://www.magpiebrain.com/blog/2004/05/17/beware-using-dateformat-for-input-validation/#comment-389</link>
		<dc:creator>Hale</dc:creator>
		<pubDate>Tue, 20 Jul 2004 17:21:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/05/17/beware-using-dateformat-for-input-validation/#comment-389</guid>
		<description>One more note:  without the dateFormat.setLenient(false), the SimpleDateFormatter will convert a date like 12/44/2004 into something like 1/13/2005.  It doesn't catch months_out_of_range or days_in_month_out_of_range errors.
</description>
		<content:encoded><![CDATA[<p>One more note:  without the dateFormat.setLenient(false), the SimpleDateFormatter will convert a date like 12/44/2004 into something like 1/13/2005.  It doesn&#8217;t catch months_out_of_range or days_in_month_out_of_range errors.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Hawkett</title>
		<link>http://www.magpiebrain.com/blog/2004/05/17/beware-using-dateformat-for-input-validation/#comment-388</link>
		<dc:creator>Colin Hawkett</dc:creator>
		<pubDate>Fri, 11 Jun 2004 16:13:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/05/17/beware-using-dateformat-for-input-validation/#comment-388</guid>
		<description>We ended up doing this to force it....

/*
 * Created on 11-Jun-04
 */
package domain;

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;

/**
 * @author Colin Hawkett
 */
public class StrictDateFormat extends SimpleDateFormat {
   public StrictDateFormat(String format) {
      super(format);
   }
	
   public java.util.Date parse(String dateString) throws ParseException {
      if(dateString.length() != toPattern.length()) throw new ParseException("Input string wrong length!", 0);
      ParsePosition pos = new ParsePosition(0);
      java.util.Date date = super.parse(dateString, pos);
      if((date == null) &#124;&#124; (pos.getErrorIndex() != -1)) throw new ParseException("Dodgy date string!", pos.getIndex());
      if(pos.getIndex() != toPattern().length()) throw new ParseException("Did not use entire string to parse date!", pos.getIndex());
      else return date;
   }
}</description>
		<content:encoded><![CDATA[<p>We ended up doing this to force it&#8230;.</p>
<p>/*</p>
<p> * Created on 11-Jun-04<br />
 */<br />
package domain;</p>
<p>import java.text.ParseException;<br />
import java.text.ParsePosition;<br />
import java.text.SimpleDateFormat;</p>
<p>/**</p>
<p> * @author Colin Hawkett<br />
 */<br />
public class StrictDateFormat extends SimpleDateFormat {<br />
   public StrictDateFormat(String format) {<br />
      super(format);<br />
   }</p>
<p>   public java.util.Date parse(String dateString) throws ParseException {<br />
      if(dateString.length() != toPattern.length()) throw new ParseException(&#8220;Input string wrong length!&#8221;, 0);<br />
      ParsePosition pos = new ParsePosition(0);<br />
      java.util.Date date = super.parse(dateString, pos);<br />
      if((date == null) || (pos.getErrorIndex() != -1)) throw new ParseException(&#8220;Dodgy date string!&#8221;, pos.getIndex());<br />
      if(pos.getIndex() != toPattern().length()) throw new ParseException(&#8220;Did not use entire string to parse date!&#8221;, pos.getIndex());<br />
      else return date;<br />
   }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joey Gibson</title>
		<link>http://www.magpiebrain.com/blog/2004/05/17/beware-using-dateformat-for-input-validation/#comment-387</link>
		<dc:creator>Joey Gibson</dc:creator>
		<pubDate>Wed, 19 May 2004 16:13:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/05/17/beware-using-dateformat-for-input-validation/#comment-387</guid>
		<description>We discovered the non-threadsafeness of SimpleDateFormat a few months ago. It bit us big time...</description>
		<content:encoded><![CDATA[<p>We discovered the non-threadsafeness of SimpleDateFormat a few months ago. It bit us big time&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Newman</title>
		<link>http://www.magpiebrain.com/blog/2004/05/17/beware-using-dateformat-for-input-validation/#comment-386</link>
		<dc:creator>Sam Newman</dc:creator>
		<pubDate>Wed, 19 May 2004 09:30:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/05/17/beware-using-dateformat-for-input-validation/#comment-386</guid>
		<description>According to the documentation, @DateFormat@ isn't synchronized either:

bq. "Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally."</description>
		<content:encoded><![CDATA[<p>According to the documentation, <code>DateFormat</code> isn&#8217;t synchronized either:</p>
<blockquote>
<p>&#8220;Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.&#8221; </p>
</blockquote>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jed Wesley-Smith</title>
		<link>http://www.magpiebrain.com/blog/2004/05/17/beware-using-dateformat-for-input-validation/#comment-385</link>
		<dc:creator>Jed Wesley-Smith</dc:creator>
		<pubDate>Wed, 19 May 2004 04:23:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.magpiebrain.com/2004/05/17/beware-using-dateformat-for-input-validation/#comment-385</guid>
		<description>Actually, I think its just SimpleDateFormat that is not thread-safe, but don't quote me. I generally use the Jakarta commons-lang 2.0 FastDateFormat class, thread-safe and quicker than SimpleDateFormat.

What context are you entering dates? There are a number of good javascript date validation scripts around, and some free Java implementations as well.

_Edited to stop layout problem_:

"Javascript Validation Links":http://www.google.com/search?num=50&#38;hl=en&#38;lr=&#38;ie=UTF-8&#38;oe=UTF-8&#38;c2coff=1&#38;q=javascriptdate validation&#38;btnG=Search</description>
		<content:encoded><![CDATA[<p>Actually, I think its just SimpleDateFormat that is not thread-safe, but don&#8217;t quote me. I generally use the Jakarta commons-lang 2.0 FastDateFormat class, thread-safe and quicker than SimpleDateFormat.</p>
<p>What context are you entering dates? There are a number of good javascript date validation scripts around, and some free Java implementations as well.</p>
<p><em>Edited to stop layout problem</em>:</p>
<p><a href="http://www.google.com/search?num=50&#038;hl=en&#038;lr=&#038;ie=UTF-8&#038;oe=UTF-8&#038;c2coff=1&#038;q=javascriptdate" >Javascript Validation Links</a> validation&#038;btnG=Search</p>
]]></content:encoded>
	</item>
</channel>
</rss>
