I am looking for a code in javascript that ensures future date validation.
e.g.If the date is 01/14/2014(format-MM/DD/YYYY) and if in the text field I try to give future date for example(01/27/2014),then it shuld give me an errori.e.
"Future date is not allowed."
I will be grateful if anybody could answer my question
Anubhav ChaudharyPosted Jan 13, 2014, 11:38 PM
Here is the code you need:
<script type="text/javascript">
function SelectDate(e) {
var PresentDay = new Date();
var dateOfBirth = e.get_selectedDate();
var months = (PresentDay.getMonth() - dateOfBirth.getMonth() +
(12 * (PresentDay.getFullYear() - dateOfBirth.getFullYear())));
document.getElementById("txtCONSULTANT_AGE").value = Math.round(months / 12);
document.getElementById("txtCONSULTANT_AGE").readOnly = true;
if (dateOfBirth > PresentDay) {
alert("error");
document.getElementById("txtCONSULTANT_AGE").value = "You are Going to Born";
}
}
script>
You can also check my these Articles for this type of validation:http://www.c-sharpcorner.com/UploadFile/cd7c2e/apply-client-side-validation-on-dob-selected-by-user/
http://www.c-sharpcorner.com/UploadFile/cd7c2e/apply-server-side-validation-on-dob-selected-by-user/