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

1 Answer 1

4

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()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.