Last active
September 10, 2017 13:04
-
-
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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i want to perform on on key up event , not working