Skip to content

Instantly share code, notes, and snippets.

@BrendanThompson
Last active September 10, 2017 13:04
Show Gist options
  • Save BrendanThompson/9633307 to your computer and use it in GitHub Desktop.
Save BrendanThompson/9633307 to your computer and use it in GitHub Desktop.
Validation to confirm that the inputted date is greater than or equal to today's date
// This validation is used inside an ASP.net WebForms application.
function dateValidation(source, args) {
var today = new Date();
var parsedInputDate = new Date(args.Value.replace(/(\d{2})\/(\d{2})\/(\d{4})/, '$3-$2-$1')); // This assumes the splitting of date parts on the input is a "/"
function stripTime(inputDate) {
var strippedInputDate = new Date(inputDate.getFullYear(), inputDate.getMonth() + 1, inputDate.getDate()); // Require to add one to the month as in JavaScript January is month 0
return strippedInputDate;
}
var strippedTodaysDate = stripTime(today);
var strippedParsedInputDate = stripTime(parsedInputDate);
if (strippedParsedInputDate >= strippedTodaysDate) {
// Date Validation Passed
} else {
// Date Validation Failed
document.getElementById(source.previousElementSibling.id).value = ''; // This will clear the textbox, and get the appropriate TextBox ID depending on what is calling the validation
}
}
@ajitagarwal89
Copy link

i want to perform on on key up event , not working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment