Click to See Complete Forum and Search --> : Disallow Past & Current Date Validation


Thene
03-29-2006, 07:45 AM
Hi :)

Currently I'm using a date picker that allows the user to pick the date from a calender and it automatically inputs into the field in this format.

29-Mar-2006

What I would like to do is validate the field on submission and return an alert if it is a post date or current date. Basically I would only like to allow the user to select dates after the current day. Eg. Today is the 29th so 30th would be first day available and so on.

I apologise in advance if this has been covered elsewhere and I missed it. I did have a look but was only able to find future date validation.

I would greatly appreciate any assistance.

Thanks Kindly,
Thene

James Gatka
03-29-2006, 08:40 AM
<html>
<head>
<script type="text/javascript">

var today = new Date();
today.setHours(0,0,0,0);

function validate(nForm){

var splitDate = nForm['nDate'].value.split("-");
var refDate = new Date(splitDate[2]+" "+splitDate[1]+" "+splitDate[0]);
if (refDate <= today)
{
alert('Must input a future date')
nForm['nDate'].value = "";
nForm['nDate'].focus();
return false;
}
}

</script>
</head>
<body>
<form method="post" action="" onsubmit="return validate(this)">

Input Date dd-mon-yyyy: <input type='text' size='12' name='nDate'>
<br>
<input type='submit' name='submit' value="Submit">

</form>
</body>
</html>

James Gatka
03-29-2006, 09:40 AM
Thene:

I edited my previous post. I forgot to include this line: return false;

Thene
03-30-2006, 09:07 PM
Thank you James, it worked beautifully.

Much appreciation for your time and generous help.

danver27
02-24-2012, 05:18 PM
hey there james, thanks for this code, its useful to me. :)