views:

25

answers:

1

Assume in my text box user enter like

18-06-2010 ,

Validation RULE if date is greater then current date then program should through the validation error like ,

PELASE ENTER PAST OR CURRENT DATE, DONT CHOOSE FUTURE DATE ,

Thanks

+2  A: 

The date format you've specified is not recognized by javascript. Here's a script that makes some minor validity checking, but still some rough assumptions that the value entered conforms to the format above, and tries to construct the date string '2010/06/08' out of that.

var txtDate = document.getElementById('myTextBox').value;
var dateParts = txtDate.split('-');

if(dateParts.length != 3) {
    alert('invalid date!');
    return false;
}

var testDate = new Date(dateParts[2] + '/' + dateParts[1] + '/' + dateParts[0]);

if(isNaN(testDate.getDate())) {
    alert('invalid date!');
    return false;
}

Implement further error checking as you see fit. Once you know testDate is a date, you can compare it the current date: testDate > new Date()

David Hedlund