Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Validation

Status
Not open for further replies.

esearing

IS-IT--Management
Aug 22, 2000
132
US
I have two Datefields on my form; "ReqDate" & "NeedByDate".

1) I need to validate that they are formatted as dates.
is there a function/method like:
if NOT isdate(document.form.field.value)
{alert("alertmessage")...}

2) I need to validate that NeedByDate > ReqDate >= Today


Thanks in advance

Eric Searing
eric.searing@wcom.com
 
this will validate that it is in correct format and is a valid date...

String.prototype.verifyDate = function()
{
var x = new Date(this);
var m = x.getMonth()+1;
m = (m < 10)?&quot;0&quot;+m:m;
var d = x.getDate();
d = (d < 10)?&quot;0&quot;+d:d;
var y = x.getFullYear();
if(m+&quot;/&quot;+d+&quot;/&quot;+y == this)
{
return true;
}
return false;
}

used like so:

if(new String(form.element.value).verifyDate())


then once you are sure they are valid dates....


var x = new Date(form.needbydate.value);
var y = new Date(form.reqdate.value);
var z = new Date();

if((x > y) && (y >= z))

you may want to set the time on the last date, otherwise it will take the curent time also, and it will say that a date in reqdate is before today even if it is today. luciddream@subdimension.com
 
Thanks!

Do I need to substitute my element names in
&quot;if(new String(form.element.value).verifyDate())&quot;?

?or anywhere else?


Eric Searing
eric.searing@wcom.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top