How to validate Date in form onblur - javascript

function validatedate(inputText) {
var thsid = $(inputText).attr('id');
var dateformat = /^(0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])[\/\-]\d{4}$/;
}
This is my common js method [incomplete] onblur="validatedate(this)" but its accepting invalid dates also
I have one datepicker in my jsp as textbox.onblur i need to validate date using javascript
these are the rules
mm/dd/yy format
mm should not exceed 31
dd should not exceed 12
should be commom method for all datepickers
if given input invalid ..should give an alert and empty datepicker..............

Change:
onblur="validatedate(this)"
To:
onblur="validatedate(this.value);"
this contains input DOM element itself and not the input's text value.
Also your validatedate() function appears to be doing nothing. There is no return value, no alert or anything to stop form processing. I take for granted you only supplied a snippet of the function itself.

Saidesh's answer got me most of the way to where I wanted, but I didn't like the JQuery dependency. I added a couple minor improvements as well as a fully functional test page.
<html>
<head>
<script type="application/javascript">
function validatedate(inputTextObject) {
// matches 11/12/2011 or 11-12-2011
var ret = true;
var dateformat = /^(0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])[\/\-]\d{4}$/;
// Match the date format through regular expression
if (inputTextObject.value.trim() != "") {
if (inputTextObject.value.trim().match(dateformat)) {
// document.form1.text1.focus();
//Test which seperator is used '/' or '-'
var opera1 = inputTextObject.value.split('/');
var opera2 = inputTextObject.value.split('-');
lopera1 = opera1.length;
lopera2 = opera2.length;
// Extract the string into month, date and year
if (lopera1 > 1) {
var pdate = inputTextObject.value.split('/');
} else if (lopera2 > 1) {
var pdate = inputTextObject.value.split('-');
}
var mm = parseInt(pdate[0]);
var dd = parseInt(pdate[1]);
var yy = parseInt(pdate[2]);
// Create list of days of a month [assume there is a leap year by default]
var ListofDays = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
if (mm == 1 || mm > 2) {
if (dd > ListofDays[mm - 1]) {
alert('Invalid date format!');
inputTextObject.focus();
ret = false;
}
}
if (mm == 2) {
var lyear = false;
if ((!(yy % 4) && yy % 100) || !(yy % 400)) {
lyear = true;
}
if ((lyear == false) && (dd >= 29)) {
alert('Invalid date format!');
inputTextObject.focus();
ret = false;
}
if ((lyear == true) && (dd > 29)) {
alert('Invalid date format!');
inputTextObject.focus();
ret = false;
}
}
} else {
alert("Invalid date format!");
inputTextObject.focus();
ret = false;
}
if (ret == false) {
inputTextObject.style.color='red';
} else {
inputTextObject.style.color='blue';
}
}
return ret;
}
</script>
</head>
<body>
Date Test (<strong>mm/dd/yyyy</strong>): <input name="date_test" type="text" onblur="validatedate(this);" />
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACYAAAAmAQMAAACS83vtAAAABlBMVEUAAAD///+l2Z/dAAAACXBIWXMAAAsTAAALEwEAmpwYAAAApElEQVQI1y3OQWpCMQBF0ZtnqF8Q286FCm7CgdgsqUv44qBuqvKXEqgLiCIokuY5qGcFJxiwcABxJoEHXhseedTkKQeony5NNdH1FLtuFEDofPc2i2sbeh0hl0jZgzoiKw1vPQhYICZKiJfQI4CFSFyyDA2FjFCCgm5fHLvIjWGs+Zo94fdvvnScOW74/6jbfdf0XClz4rnl530KLnw0XHELBvwAwg1K5dfpv8IAAAAASUVORK5CYII=" />
</body>
</html>

Now my method is ready..with the help of stackoverflow:
function validatedate(inputText)
{
var thsid=$(inputText).attr('id');
var classname=$(inputText).attr('class');
var classstr=classname.split(" ");
var ret=true;
var dateformat = /^(0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])[\/\-]\d{4}$/;
// Match the date format through regular expression
if(inputText.value.trim()!="")
{
if( inputText.value.trim().match(dateformat))
{
// document.form1.text1.focus();
//Test which seperator is used '/' or '-'
var opera1 = inputText.value.split('/');
var opera2 = inputText.value.split('-');
lopera1 = opera1.length;
lopera2 = opera2.length;
// Extract the string into month, date and year
if (lopera1>1)
{
var pdate = inputText.value.split('/');
}
else if (lopera2>1)
{
var pdate = inputText.value.split('-');
}
var mm = parseInt(pdate[0]);
var dd = parseInt(pdate[1]);
var yy = parseInt(pdate[2]);
// Create list of days of a month [assume there is no leap year by default]
var ListofDays = [31,28,31,30,31,30,31,31,30,31,30,31];
if (mm==1 || mm>2)
{
if (dd>ListofDays[mm-1])
{
alert('Invalid date format!');
$(inputText).focus();
inputText.value="";
ret=false;
return false;
}
}
if (mm==2)
{
var lyear = false;
if ( (!(yy % 4) && yy % 100) || !(yy % 400))
{
lyear = true;
}
if ((lyear==false) && (dd>=29))
{
alert('Invalid date format!');
$('#'+thsid).focus();
inputText.value="";
ret=false;
return false;
}
if ((lyear==true) && (dd>29))
{
alert('Invalid date format!');
$('#'+thsid).focus();
inputText.value="";
ret=false;
return false;
}
}
}
else
{
alert("Invalid date format!");
$('#'+thsid).focus();
inputText.value="";
ret=false;
return false;
}
}

Related

javascript validate birthday

im trying to validate birth numbers with a simple script but this script returns true even tho i type in a month over 12 and day over 31, so what have i missed?
var as = /^[0-9]{6}[-+][0-9]{4}$/;
var pn=document.forms.kontakt.pnr.value;
if (as.test(pn)) {
var year = pn.substr(0,2);
var month = pn.substr(2,2);
var day = pn.substr(4,2);
if (month <= 13 && day <= 32) {
return true;
}
} else {
alert ("Fyll i korrekt personnummer xxxxxx-xxxx");
kontakt.pnr.style.background = "red";
return false;
}
The if/else statement is fine, the problem is probably in your substr or regex.
I would console.log your "month" and "day" variables to narrow down your bug.
var as = /^[0-9]{6}-[0-9]{4}$/;
var pn = document.forms.kontakt.pnr.value;
if (as.test(pn)) {
var year = pn.substr(0,2);
var month = pn.substr(2,2);
var day = pn.substr(4,2);
if (month > 12 || day > 31) {
alert("Fyll i korrekt personnummer"); siffror
kontakt.pnr.style.background = "red";
return false;
}
else {
return true;
}
}
else {
alert("Fyll i personnummer i formatet xxxxxx-xxxx");
kontakt.pnr.style.background = "red";
return false;
}
This was the solution for me!

Adding one more event in JQuery date picker the current adding functionalities not working

Currently working on calculating the year using jquery. This was working perfectly as expected but I want to add one more function into it. If the user enters a wrong value for example 121212 it should say "You have entered the wrong format. Kindly enter the correct format".
$('.startDate').change(function(event) {
var txtVal6 = $(this).val();
//alert("check what" + txtVal);
if (isDate5(txtVal6)) {
$(this).removeClass("errRed");
event.stopImmediatePropagation();
} else {
alert('Kindly enter date in valid format');
$(this).addClass("errRed").val("");
event.stopImmediatePropagation();
}
});
function isDate5(startDate) {
var currVal6 = startDate;
if (currVal6 == '') return false;
var rxDatePattern6 = /^\d{2}[./-]\d{2}[./-]\d{4}$/; //Declare Regex
var dtArray6 = currVal6.match(rxDatePattern6); // is format OK?
if (dtArray6 == null) return false;
//Checks for mm/dd/yyyy format.
dtMonth6 = dtArray6[3];
dtDay6 = dtArray6[5];
dtYear6 = dtArray6[1];
if (dtMonth6 < 1 || dtMonth6 > 12) return false;
else if (dtDay6 < 1 || dtDay6 > 31) return false;
else if ((dtMonth6 == 4 || dtMonth6 == 6 || dtMonth6 == 9 || dtMonth6 == 11) && dtDay6 == 31) return false;
else if (dtMonth6 == 2) {
var isleap = (dtArray6 % 4 == 0 && (dtArray6 % 100 != 0 || dtArray6 % 400 == 0));
if (dtDay6 > 29 || (dtDay6 == 29 && !isleap)) return false;
}
return true;
}
$('.endDate').change(function(event) {
var txtVal7 = $(this).val();
//alert("check what" + txtVal);
if (isDate6(txtVal7)) {
$(this).removeClass("errRed");
event.stopImmediatePropagation();
} else {
alert('Kindly enter date in valid format');
$(this).addClass("errRed").val("");
event.stopImmediatePropagation();
}
});
function isDate6(endDate) {
var currVal7 = endDate;
if (currVal7 == '') return false;
var rxDatePattern7 = /^\d{2}[./-]\d{2}[./-]\d{4}$/; //Declare Regex
var dtArray7 = currVal7.match(rxDatePattern7); // is format OK?
if (dtArray7 == null) return false;
//Checks for mm/dd/yyyy format.
dtMonth7 = dtArray7[3];
dtDay7 = dtArray7[5];
dtYear7 = dtArray7[1];
if (dtMonth7 < 1 || dtMonth7 > 12) return false;
else if (dtDay7 < 1 || dtDay7 > 31) return false;
else if ((dtMonth7 == 4 || dtMonth7 == 6 || dtMonth7 == 9 || dtMonth7 == 11) && dtDay7 == 31) return false;
else if (dtMonth7 == 2) {
var isleap = (dtArray7 % 4 == 0 && (dtArray7 % 100 != 0 || dtArray7 % 400 == 0));
if (dtDay7 > 29 || (dtDay7 == 29 && !isleap)) return false;
}
return true;
}
With this code if I enter the value 12112 in the text field to date field it says kindly enter the correct value but if i enter the correct date value in from and to field the calculating of the years is not working.
Thanks in advance
Here is the fiddle link
Don't know why you just don't use Javascript built in Date object, anyway, I did some changes inside your script, starting from RegExp and removing some functions which, imho, weren't useful.
This is what I've done:
var dateRegex=new RegExp("^[0-9]{2}-[0-9]{2}-[0-9]{4}$");
$(document).on('change', ".datepicker", function() {
// No need for each() part, you already know which one is the start and which one is the end
if($(this).val()){
if(!dateRegex.test($(this).val())){
alert('Kindly enter date in valid format');
$(this).val('');
return false;
}
}
if($(".startDate").val() && $(".endDate").val()){
var dateStart = $(".datepicker.startDate").val(),
dateEnd = $(".datepicker.endDate").val();
// No need even for array, you just get datepicker value like this and test it
var dateStartArray=dateStart.split('-'),dateEndArray=dateEnd.split('-');
var fromdate=new Date(dateStartArray[2],dateStartArray[0]-1,dateStartArray[0]),
todate=new Date(dateEndArray[2],dateEndArray[0]-1,dateEndArray[0]);
// Creating date object with format YYYY-MM-GG ( taken from datepicker's split array )
console.log(fromdate);
console.log(todate);
if(fromdate>todate){
alert("To date should be greater than from date");
return false;
} else {
var yearsDifference=todate.getFullYear()-fromdate.getFullYear();
var monthsDifference=(todate.getMonth()+12*todate.getFullYear())-(fromdate.getMonth()+12*fromdate.getFullYear());
$("#txt_expy").html(Math.floor(monthsDifference/12)+' Years');
$("#txt_expm").html((monthsDifference%12)+' Months');
}
} else {
return false;
}
});
You can check this fiddle to see all the modifies I've done, see if this can help :)
Update code
var diffDays = 0;
$(".cloned-row3").find(".datepicker").removeClass('hasDatepicker').datepicker({
dateFormat: "mm-dd-yy",
changeMonth: true,
yearRange: "-100:+0",
changeYear: true,
maxDate: new Date(),
showButtonPanel: false,
beforeShow: function() {
setTimeout(function() {
$('.ui-datepicker').css('z-index', 99999999999999);
}, 0);
}
});
var count = 0;
$(document).on("click", ".exp_add_button", function() {
var $clone = $('.cloned-row3:eq(0)').clone(true, true);
$clone.find('[id]').each(function() {
this.id += 'someotherpart'+count;
});
$clone.find('.btn_more').after("<input type='button' class='btn_less1 selbtnless' id='buttonless' value='remove'/>")
$clone.attr('id', "added" + (++count));
$clone.find(".startDate").val('');
$clone.find(".endDate").val('');
/*$clone.find(".degree_Description").attr('disabled', true).val('');*/
$clone.find("input.startDate").removeClass('hasDatepicker').removeData('datepicker')
.unbind()
.datepicker({
dateFormat: "mm-dd-yy",
changeMonth: true,
yearRange: "-100:+0",
changeYear: true,
maxDate: new Date(),
showButtonPanel: false,
beforeShow: function() {
setTimeout(function() {
$('.ui-datepicker').css('z-index', 99999999999999);
}, 0);
}
});
$clone.find("input.endDate")
.removeClass('hasDatepicker')
.removeData('datepicker')
.unbind()
.datepicker({
dateFormat: "mm-dd-yy",
changeMonth: true,
yearRange: "-100:+0",
changeYear: true,
maxDate: new Date(),
showButtonPanel: false,
beforeShow: function() {
setTimeout(function() {
$('.ui-datepicker').css('z-index', 99999999999999);
}, 0);
}
});
$(this).parents('.wrk_exp').after($clone);
});
$(document).on('click', ".btn_less1", function() {
var len = $('.cloned-row3').length;
if(len > 1) {
var RemoveStartDate = $(this).closest(".btn_less1").parent().parent().parent().find('.startDate ').val();
var RemoveEndDate = $(this).closest(".btn_less1").parent().parent().parent().find('.endDate ').val();
if((RemoveStartDate!='')||(RemoveEndDate!='')){
var dateStartArray=RemoveStartDate.split('-'),dateEndArray=RemoveEndDate.split('-');
var fromdate=new Date(dateStartArray[2],dateStartArray[0]-1,dateStartArray[0]),
todate=new Date(dateEndArray[2],dateEndArray[0]-1,dateEndArray[0]);
var yearsDifference=todate.getFullYear()-fromdate.getFullYear();
var monthsDifference=(todate.getMonth()+12*todate.getFullYear())-(fromdate.getMonth()+12*fromdate.getFullYear());
var PrevTotalYear = parseInt($("#txt_expy>span").text());
var PrevTotalMonth = parseInt($("#txt_expm>span").text());
$("#txt_expy>span").text('');
$("#txt_expm>span").text('');
PrevTotalYear = PrevTotalYear*12;
var CurTotalYear = Math.floor(((PrevTotalYear+PrevTotalMonth)-monthsDifference)/12);
var CurTotalMonth = (monthsDifference-PrevTotalMonth)%12;
$("#txt_expy>span").text(CurTotalYear);
$("#txt_expm>span").text(CurTotalMonth);
$(this).closest(".btn_less1").parent().parent().parent().remove();
}else{
$(this).closest(".btn_less1").parent().parent().parent().remove();
}
}
});
$(document).on('change', ".datepicker", function() {
// No need for each() part, you already know which one is the start and which one is the end
dateRegex=new RegExp("^[0-9]{2}-[0-9]{2}-[0-9]{4}$");
if($(this).hasClass('startDate')) {
var dateStart = $(this).val();
if(!dateRegex.test(dateStart)){
alert('Kindly enter date in valid format');
return false;
}
return false;
}
else if($(this).hasClass('endDate') && isNaN($(this).val())|| $(this).val()!='') {
var dateEnd = $(this).val();
if(!dateRegex.test(dateEnd)){
alert('Kindly enter date in valid format');
return false;
}else{
dateStart = $(this).closest('.row').find('.startDate').val();
}
}else{
return false;
}
if((dateStart!='')||(dateEnd!='')){
// No need even for array, you just get datepicker value like this and test it
var dateStartArray=dateStart.split('-'),dateEndArray=dateEnd.split('-');
var fromdate=new Date(dateStartArray[2],dateStartArray[0]-1,dateStartArray[0]),
todate=new Date(dateEndArray[2],dateEndArray[0]-1,dateEndArray[0]);
// Creating date object with format YYYY-MM-GG ( taken from datepicker's split array )
if(fromdate>todate){
alert("To date should be greater than from date");
return false;
} else {
var yearsDifference=todate.getFullYear()-fromdate.getFullYear();
var monthsDifference=(todate.getMonth()+12*todate.getFullYear())-(fromdate.getMonth()+12*fromdate.getFullYear());
var PrevTotalYear = parseInt($("#txt_expy>span").text());
var PrevTotalMonth = parseInt($("#txt_expm>span").text());
$("#txt_expy>span").text('');
$("#txt_expm>span").text('');
PrevTotalYear = PrevTotalYear*12;
var CurTotalYear = Math.floor((monthsDifference+PrevTotalYear+PrevTotalMonth)/12);
var CurTotalMonth = (monthsDifference+PrevTotalMonth)%12;
$("#txt_expy>span").text(CurTotalYear);
$("#txt_expm>span").text(CurTotalMonth);
}
}
else {
return false;
}
});
fiddle link

JavaScript date throws Invalid Date

i am trying to compare two dates from date and to date following is my method :
function isValidDate() {
var fromDate ="";
var toDate ="";
var fromDateTemp = $("#fromRequestDate").val(); //2013-12-05
var toDateTemp = $("#toRequestDate").val(); //2013-12-01
if(fromDateTemp.length != '0' && toDateTemp.length != '0'){
fromDate = new Date(fromDateTemp);
toDate = new Date(toDateTemp);
}
if (fromDate.length != '0' || toDate.length != '0') {
$("#validationMessage").text("Please Select From Date and To Date");
return false;
} else if (fromDate.getDate() > toDate.getDate()) {
$("#validationMessage").text("From Date is greater than To Date");
return false;
} else {
$("#validationMessage").text("");
return true;
}
}
but i get Ivalid Date as well as undefined when calculating length.
so please help me to find the issue.
Thanks
We usually compare two Dates using getTime (it returns the number of milliseconds passed since 1970)
So,
fromDate.getTime() > toDate.getTime()
ought to work. Assuming, of course, that the values being taken from the #fromReqDate and #toReqDate are instances of Date (simple check fromDate instanceOf Date should return true)
Try using this.
if(isNaN(new Date(fromDateTemp)))
{
alert("Please enter a valid from date");
return;
}
var fromDateTemp = $("#fromRequestDate").val(); //2013-12-05
var toDateTemp = $("#toRequestDate").val(); //2013-12-01
instead of these two code just replace the following codes
var fromDateTemp = new Date(''+$("#fromRequestDate").val()); //2013-12-05
var toDateTemp = new Date(''+$("#toRequestDate").val()); //2013-12-01
I think mistake is in your condition checking if (fromDate.length == '0' || toDate.length == '0') instead of this you used if(fromDateTemp.length != '0' && toDateTemp.length != '0') check the code and revert if you are facing issue still.
var fromDate ="";
var toDate ="";
var fromDateTemp = '2013-12-05'; //2013-12-05
var toDateTemp = '2013-12-01'; //2013-12-01
if(fromDateTemp.length != '0' && toDateTemp.length != '0'){
fromDate = new Date(fromDateTemp);
toDate = new Date(toDateTemp);
}
if (fromDate.length == '0' || toDate.length == '0') {
alert("Please Select From Date and To Date");
return false;
} else if (fromDate.getDate() > toDate.getDate()) {
alert("From Date is greater than To Date");
return false;
} else {
alert("");
return true;
}
Here's corrected js:
Demo
function isValidDate() {
var fromDate = null;
var toDate = null;
var fromDateTemp = $("#fromRequestDate").val();
var toDateTemp = $("#toRequestDate").val();
if(fromDateTemp.length != 0 && toDateTemp.length != 0){
fromDate = new Date(fromDateTemp);
toDate = new Date(toDateTemp);
}
if (fromDate == null || toDate == null) {
$("#validationMessage").text("Please Select From Date and To Date");
return false;
} else if (fromDate.getTime() > toDate.getTime()) {
$("#validationMessage").text("From Date is greater than To Date");
return false;
} else {
$("#validationMessage").text("");
return true;
}
}

Formatting an user input date.

Is there a better way to format a date imputed by a user. I have an input field where when clicked on a calender pops up and you can chose a date but the user also has the option to type in the date. I want the user to be able to type in 1/12 and my javascript to format it to 01/12/2012. Is there an easy way to go about this with out having to do all types of checks? If not what is the best way to go about this?
I've just gave it a try but not sure if it's the proper way but I think it's working (month/day/year).
$('input[name="txt_date"]').on('blur', function(e){
var dt=$(this).val();
if(dt!='')
{
if(dt.indexOf('/'))
{
var da=dt.split('/');
var l=da.length;
if(l <= 3)
{
var date='';
for(i=0;i<l;i++)
{
if(i==0)
{
if(da[i].match(/^\d{1}|d{2}$/) && da[i]>0 && da[i]<=12)
{
var m=da[i].length==1 ? '0'+da[i] : da[i];
date=m;
}
}
if(i==1)
{
if(da[i].match(/^\d{1}|d{2}$/) && da[i]>0 && da[i]<=31)
{
var d=da[i].length==1 ? '0'+da[i] : da[i];
date+='/'+d;
}
}
if(i==2)
{
if(da[i].match(/^\d{4}$/))
{
date+='/'+da[i];
}
else date+='/'+new Date().getFullYear();
}
}
if(l<3)
{
date+='/'+new Date().getFullYear();
}
if(date.match(/^\d{2}\/\d{2}\/\d{4}$/))
{
$(this).val(date);
}
else alert('invalid date!');
}
}
}
});
DEMO.
This library could help you: http://www.datejs.com/
dd/mm/yyyy is a valid format e.g. in Spain, UK, ...
Here's what I came up with.
var checkDate = function(dateVal, input){
if(dateVal.length == 10){
return;
}
var d = new Date();
var currentMonth = d.getMonth();
var year = d.getFullYear();
var firstIndex = dateVal.indexOf('/');
var month = parseInt(dateVal.substr(0, firstIndex));
var day = parseInt(dateVal.substr(firstIndex + 1, 2));
if(month < 10){
month = '0' + month;
}
if(day < 10){
day = '0' + day;
}
if(month > currentMonth){
year = year - 1;
}
dateVal = month + '/' + day + '/' + year;
if(isNaN(month)){
input.val('');
return;
}
input.val(dateVal);
};

JavaScript to validate date

Below is the function to validate date. The should be between Today - 15 and Today. Can some one refactor this code.
phpdatetoday is a string in the form 2010,Dec,3
function validate(page, phpdatetoday)
{
var i = 0;
var fields = new Array();
var fieldname = new Array();
var day = document.getElementById('date_of_inspection_day').value;
var month = document.getElementById('date_of_inspection_month').value;
var year = document.getElementById('date_of_inspection_year').value;
var datesubmitted = new Date(year,month-1,day);
var daysInMonth = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
if(month.length<1 )
{
alert("Please enter a valid month");
return false;
}
if(year.length != 4 )
{
alert("Please enter a valid year");
return false;
}
if (day.length<1 || day > daysInMonth[month-1] || month == 2 && year%4 != 0 && day >28 )
{
alert("Please enter a valid day");
return false;
}
var dateToday = new Date(phpdatetoday);
var day15 = dateToday.getDate()-15; // 15 days old
var month15 = dateToday.getMonth();
var year15 = dateToday.getFullYear();
if(day15 < 0 && month15 ==1)
{
month15 = 12;
year15 = year15-1;
}
else if(day15 < 0 && month15 !=1)
{
month15 = month15-1;
}
day15 = daysInMonth[month15-1] + day15;
var date15DayOld = new Date(year15,month15,day15);
if(date15DayOld > datesubmitted )
{
alert("Your date is older than 15 days");
}
else if(datetoday < datesubmitted )
{
alert("invalid Date");
}
}
function validate(phpdatetoday, withinDays) {
var inputDateInMillis = Date.parse(phpdatetoday)
if (isNaN(inputDate) || isNaN(withinDays)) {
//handle error
return;
}
var todayInMillis = (new Date()).setHours(0,0,0,0);
return todayInMillis - inputDateInMillis < (withinDays * 86400000 /*1000ms*60s*60m*24h*/);
}
Date.setHours() will set the hours/minutes/seconds to zero and return milliseconds since 1 Jan 1970 UTC.
Date.parse() will return the parsed date otherwise if it cannot do it then it will return NaN. You can use isNan() to determine whether a variable's value is a number or not. If 'inputDate' is NaN then you can alert the user that the input date was invalid.
eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('C K(L,w){3 i=0;3 H=b q();3 I=b q();3 c=k.t(\'J\').s;3 9=k.t(\'G\').s;3 d=k.t(\'A\').s;3 u=b j(d,9-1,c);3 l=b q(7,E,7,g,7,g,7,7,g,7,g,7);6(9.n<1){e("v r a p 9");m o}6(d.n!=4){e("v r a p d");m o}6(c.n<1||c>l[9-1]||9==2&&d%4!=0&&c>R){e("v r a p c");m o}3 f=b j(w);3 8=f.N()-y;3 5=f.Q();3 h=f.P();6(8<0&&5==1){5=O;h=h-1}x 6(8<0&&5!=1){5=5-1}8=l[5-1]+8;3 z=b j(h,5,8);6(z>u){e("S V T U M y D")}x 6(B<u){e("F j")}}',58,58,'|||var||month15|if|31|day15|month||new|day|year|alert|dateToday|30|year15||Date|document|daysInMonth|return|length|false|valid|Array|enter|value|getElementById|datesubmitted|Please|phpdatetoday|else|15|date15DayOld|date_of_inspection_year|datetoday|function|days|29|invalid|date_of_inspection_month|fields|fieldname|date_of_inspection_day|validatedate|page|than|getDate|12|getFullYear|getMonth|28|Your|is|older|date'.split('|'),0,{}))
function validate(page, phpdatetoday){return validatedate(page, phpdatetoday);}
refactored!(?)

Categories