<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: JavaScript date validation</title>
	<atom:link href="http://www.redips.net/javascript/date-validation/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redips.net/javascript/date-validation/</link>
	<description>Techniques and Web Technologies</description>
	<lastBuildDate>Sat, 04 Feb 2012 16:29:46 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/</generator>
	<item>
		<title>By: Will</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4989</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Thu, 26 Jan 2012 16:06:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4989</guid>
		<description>@dbunic That is a creative solution. I was expecting some way to access the MinDate and MaxDate on the MyStuff:DateValidator line from within the JavaScript function. But this works too. 
Thanks for your help!</description>
		<content:encoded><![CDATA[<p>@dbunic That is a creative solution. I was expecting some way to access the MinDate and MaxDate on the MyStuff:DateValidator line from within the JavaScript function. But this works too.<br />
Thanks for your help!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dbunic</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4980</link>
		<dc:creator>dbunic</dc:creator>
		<pubDate>Wed, 25 Jan 2012 08:20:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4980</guid>
		<description>@Will - Maybe you can prepare min/max date with aspx logic as hidden parameters within each form like this:
&lt;pre class=&quot;brush:text&quot;&gt;
&lt;form method=&quot;get&quot; action=&quot;some_script.aspx&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;minDate&quot; value=&quot;01/01/1940&quot;/&gt;
&lt;input type=&quot;hidden&quot; name=&quot;maxDate&quot; value=&quot;12/31/2011&quot;/&gt;
...
&lt;/pre&gt;
After date range is on the client side it easy to access and use for validation. Here is how to access dates from first form (second form will have index 1):
&lt;pre class=&quot;brush:js&quot;&gt;
// set form reference and minDate/maxDate
var frm = document.forms[0],
    minDate = frm.minDate.value,
    maxDate = frm.maxDate.value;
// display minDate and maxDate
alert(minDate + &#039; &#039; + maxDate);
&lt;/pre&gt;
Hope this hint will give you a direction of how to use date ranges for validation. If you&#039;ll have any other question, please don&#039;t hesitate to comment.</description>
		<content:encoded><![CDATA[<p>@Will - Maybe you can prepare min/max date with aspx logic as hidden parameters within each form like this:</p>
<pre class="brush:text">
&lt;form method="get" action="some_script.aspx">
&lt;input type="hidden" name="minDate" value="01/01/1940"/>
&lt;input type="hidden" name="maxDate" value="12/31/2011"/>
...
</pre>
<p>After date range is on the client side it easy to access and use for validation. Here is how to access dates from first form (second form will have index 1):</p>
<pre class="brush:js">
// set form reference and minDate/maxDate
var frm = document.forms[0],
    minDate = frm.minDate.value,
    maxDate = frm.maxDate.value;
// display minDate and maxDate
alert(minDate + ' ' + maxDate);
</pre>
<p>Hope this hint will give you a direction of how to use date ranges for validation. If you'll have any other question, please don't hesitate to comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4974</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Tue, 24 Jan 2012 16:50:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4974</guid>
		<description>@dbunic
Thanks - I&#039;ll try again.

What I am searching for is a way to access a stated MinDate and MaxDate from our forms (different for each form) and use them in the JavaScript to complete the validation. Here is a snippet of my code in ASPX:

&lt;pre class=&quot;brush:text&quot;&gt;
&lt;MyStuff:DateTextBox ID=&quot;adate&quot; runat=&quot;Server&quot; Pattern=&quot;MM/dd/yyyy&quot; /&gt;
&lt;MyStuff:DateValidator ID=&quot;dateValidator&quot; runat=&quot;Server&quot; ControlToValidate=&quot;adate&quot; ErrorMessage=&quot;Please enter a date in the following format {0} that falls between {1} and {2}.&quot; MinDate=&quot;1/1/1940&quot; MaxDate=&quot;12/31/2011&quot; /&gt;
&lt;/pre&gt;

Later in my JavaScript validation function (here I just show the header)

&lt;pre class=&quot;brush:js&quot;&gt;
function DateValidatorEvaluateIsValid(val) {
    var control = document.getElementById(val.controltovalidate);
&lt;/pre&gt;

I can get into the validation code and do the validating on the client(i.e. confirm it is a date, etc). I just can&#039;t find a way to access and use the min and max dates within that same JavaScript. If I hard code a MaxDate and Mindate I can use them to validate. So, the function will work as desired when I can access the Min and Max Dates from the form. Any insight/help would be greatly appreciated!</description>
		<content:encoded><![CDATA[<p>@dbunic<br />
Thanks - I'll try again.</p>
<p>What I am searching for is a way to access a stated MinDate and MaxDate from our forms (different for each form) and use them in the JavaScript to complete the validation. Here is a snippet of my code in ASPX:</p>
<pre class="brush:text">
&lt;MyStuff:DateTextBox ID="adate" runat="Server" Pattern="MM/dd/yyyy" /&gt;
&lt;MyStuff:DateValidator ID="dateValidator" runat="Server" ControlToValidate="adate" ErrorMessage="Please enter a date in the following format {0} that falls between {1} and {2}." MinDate="1/1/1940" MaxDate="12/31/2011" /&gt;
</pre>
<p>Later in my JavaScript validation function (here I just show the header)</p>
<pre class="brush:js">
function DateValidatorEvaluateIsValid(val) {
    var control = document.getElementById(val.controltovalidate);
</pre>
<p>I can get into the validation code and do the validating on the client(i.e. confirm it is a date, etc). I just can't find a way to access and use the min and max dates within that same JavaScript. If I hard code a MaxDate and Mindate I can use them to validate. So, the function will work as desired when I can access the Min and Max Dates from the form. Any insight/help would be greatly appreciated!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dbunic</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4968</link>
		<dc:creator>dbunic</dc:creator>
		<pubDate>Tue, 24 Jan 2012 08:22:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4968</guid>
		<description>@Will - I changed instructions below comment. Now you can see HTML elements that can be used in comment (any other HTML tag will be stripped). Anyway, before posting JS code or HTML you can (or should) replace every occurence of:
&lt;pre class=&quot;brush:text&quot;&gt;
&quot;&lt;&quot; with &quot;&lt;&quot;
&lt;/pre&gt;
... (just make search and replace before posting). After your comment is posted, I will place it inside box to be easier for reading. Thanks!</description>
		<content:encoded><![CDATA[<p>@Will - I changed instructions below comment. Now you can see HTML elements that can be used in comment (any other HTML tag will be stripped). Anyway, before posting JS code or HTML you can (or should) replace every occurence of:</p>
<pre class="brush:text">
"&lt;" with "&amp;lt;"
</pre>
<p>... (just make search and replace before posting). After your comment is posted, I will place it inside box to be easier for reading. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4964</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Mon, 23 Jan 2012 18:48:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4964</guid>
		<description>@dbunic Say, how do I include blocks of code here? I suspect I need to insert some special code or something. Thanks!</description>
		<content:encoded><![CDATA[<p>@dbunic Say, how do I include blocks of code here? I suspect I need to insert some special code or something. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4963</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Mon, 23 Jan 2012 18:47:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4963</guid>
		<description>@dbunic - Thanks for the reply. Unfortunately my code snippet did not get included, so I was not clear in my question.
I&#039;ll try to include the code. Here is part of my form:





Later in the validation function
&lt;pre class=&quot;brush:js&quot;&gt;
function DateValidatorEvaluateIsValid(val) {
    var control = document.getElementById(val.controltovalidate);
&lt;/pre&gt;
I can check for a valid date format but do not know how to get the MinDate and MaxDate from the form to test in the function.</description>
		<content:encoded><![CDATA[<p>@dbunic - Thanks for the reply. Unfortunately my code snippet did not get included, so I was not clear in my question.<br />
I'll try to include the code. Here is part of my form:</p>
<p>Later in the validation function</p>
<pre class="brush:js">
function DateValidatorEvaluateIsValid(val) {
    var control = document.getElementById(val.controltovalidate);
</pre>
<p>I can check for a valid date format but do not know how to get the MinDate and MaxDate from the form to test in the function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dbunic</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4958</link>
		<dc:creator>dbunic</dc:creator>
		<pubDate>Mon, 23 Jan 2012 07:48:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4958</guid>
		<description>@Will - you need to compare dates. Here is small JS code for a such function:
&lt;pre class=&quot;brush:js&quot;&gt;
// compare dates and return number of days between
function cmpDate(dat1, dat2) {
    var day = 1000 * 60 * 60 * 24, // milliseconds in one day
        mSec1, mSec2;              // milliseconds for dat1 and dat2
    // valudate dates
    if (!isDate(dat1) &#124;&#124; !isDate(dat2)) {
        alert(&quot;cmpDate: Input parameters are not dates!&quot;);
        return 0;
    }
    // prepare milliseconds for dat1 and dat2
    mSec1 = (new Date(dat1.substring(6, 10), dat1.substring(0, 2) - 1, dat1.substring(3, 5))).getTime();
    mSec2 = (new Date(dat2.substring(6, 10), dat2.substring(0, 2) - 1, dat2.substring(3, 5))).getTime();
    // return number of days (positive or negative)
    return Math.ceil((mSec2 - mSec1) / day);
}
&lt;/pre&gt;
... and example of how to use it:
&lt;pre class=&quot;brush:js&quot;&gt;
var dat1 = &#039;01/23/2011&#039;,
    dat2 = &#039;01/24/2011&#039;;
    
if (cmpDate(dat1, dat2) &gt; 0) {
    alert(&#039;Dat1 is prior dat2!&#039;);
}
else if (cmpDate(dat1, dat2) &lt; 0) {
    alert(&#039;Dat1 is after dat2!&#039;);
}
else {
    alert(&#039;Dat1 and dat2 are the same!&#039;);
}
&lt;/pre&gt;
Hope this will help.</description>
		<content:encoded><![CDATA[<p>@Will - you need to compare dates. Here is small JS code for a such function:</p>
<pre class="brush:js">
// compare dates and return number of days between
function cmpDate(dat1, dat2) {
    var day = 1000 * 60 * 60 * 24, // milliseconds in one day
        mSec1, mSec2;              // milliseconds for dat1 and dat2
    // valudate dates
    if (!isDate(dat1) || !isDate(dat2)) {
        alert("cmpDate: Input parameters are not dates!");
        return 0;
    }
    // prepare milliseconds for dat1 and dat2
    mSec1 = (new Date(dat1.substring(6, 10), dat1.substring(0, 2) - 1, dat1.substring(3, 5))).getTime();
    mSec2 = (new Date(dat2.substring(6, 10), dat2.substring(0, 2) - 1, dat2.substring(3, 5))).getTime();
    // return number of days (positive or negative)
    return Math.ceil((mSec2 - mSec1) / day);
}
</pre>
<p>... and example of how to use it:</p>
<pre class="brush:js">
var dat1 = '01/23/2011',
    dat2 = '01/24/2011';

if (cmpDate(dat1, dat2) > 0) {
    alert('Dat1 is prior dat2!');
}
else if (cmpDate(dat1, dat2) &lt; 0) {
    alert('Dat1 is after dat2!');
}
else {
    alert('Dat1 and dat2 are the same!');
}
</pre>
<p>Hope this will help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Will</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4951</link>
		<dc:creator>Will</dc:creator>
		<pubDate>Fri, 20 Jan 2012 19:37:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4951</guid>
		<description>Hi. Thanks for the great code and discussion. What I am searching for is a way to access a stated MinDate and MaxDate from our forms (different for each form) and use them in the JavaScript to complete the validation. (I&#039;m using ASPX)
Here is a snippet of my code:




I can get into the validation code and do the validating on the client. I just can&#039;t find a way to access and use the min and max dates within that same JavaScript.

Thanks in advance!</description>
		<content:encoded><![CDATA[<p>Hi. Thanks for the great code and discussion. What I am searching for is a way to access a stated MinDate and MaxDate from our forms (different for each form) and use them in the JavaScript to complete the validation. (I'm using ASPX)<br />
Here is a snippet of my code:</p>
<p>I can get into the validation code and do the validating on the client. I just can't find a way to access and use the min and max dates within that same JavaScript.</p>
<p>Thanks in advance!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ragha</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4941</link>
		<dc:creator>Ragha</dc:creator>
		<pubDate>Tue, 17 Jan 2012 21:05:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4941</guid>
		<description>Thank you so much for this code. With slight modifications I have been able to validate YYYY-MM-DD</description>
		<content:encoded><![CDATA[<p>Thank you so much for this code. With slight modifications I have been able to validate YYYY-MM-DD</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dbunic</title>
		<link>http://www.redips.net/javascript/date-validation/comment-page-3/#comment-4884</link>
		<dc:creator>dbunic</dc:creator>
		<pubDate>Thu, 05 Jan 2012 08:43:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.redips.net/?p=45#comment-4884</guid>
		<description>@gondai - The full code for testing date is already shown. In &lt;em&gt;onclick&lt;/em&gt; event listener of &lt;strong&gt;Check the date&lt;/strong&gt; button checkDate() function is called. You can see how alert is displayed depending on return value from isDate() function. The nice part of Web is that nothing can be hidden. You can always peek under the hood and see the source of any component of HTML page (except Flash). Yes, scripts can be minimized and hard to read, but there is option to un-minimize and beautify the code.</description>
		<content:encoded><![CDATA[<p>@gondai - The full code for testing date is already shown. In <em>onclick</em> event listener of <strong>Check the date</strong> button checkDate() function is called. You can see how alert is displayed depending on return value from isDate() function. The nice part of Web is that nothing can be hidden. You can always peek under the hood and see the source of any component of HTML page (except Flash). Yes, scripts can be minimized and hard to read, but there is option to un-minimize and beautify the code.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

