
Amend some Javascript validation code for a date picker so tomorrows date is excluded
- or -
Post a project like this4378
£35(approx. $45)
- Posted:
- Proposals: 3
- Remote
- #223022
- Awarded
Description
Experience Level: Intermediate
I have a web form on a Joomla website using BreezingForms. It includes a date picker so visitors can choose a booking date.
I currently have some validation code on the form submission routine that alerts if the date is in the past, is a Sunday or is todays date, but I also need it to alert if the visitor selects tomorrows date.
Hopefully this is a quick and easy bit of coding for someone who knows Javascript, current code is below. I don't mind if this is adjusted or its completely re-written, whatever is easier so long as it alerts for past dates, today or tomorrow and Sundays.
function ff_date_validation(element, message)
{
var data = element.value ;
data = data.replace("/","-");
var dmy = data.split("-");
if (dmy.length != 3)
{
return ( message == '' ) ? message : " Please tell us which day you'd like the service to take place " ;
}
var vDate = new Date(dmy[2] - 0, dmy[1] -1, dmy[0] - 0,0,0,0,0);
//alert(vDate);
var today = new Date();
//alert(today);
if(vDate.getTime() 1)
{
return "Unfortunately we cannot take bookings for today or tomorrow.";
}
}
else
{
return "The date cannot be in the past.";
}
}
if ((vDate.getDay() == 0) || (vDate.getDay() == 7))
{
return "Unfortunately we cannot take bookings on Sundays";
}
return '';
} // ff_date_validation
I currently have some validation code on the form submission routine that alerts if the date is in the past, is a Sunday or is todays date, but I also need it to alert if the visitor selects tomorrows date.
Hopefully this is a quick and easy bit of coding for someone who knows Javascript, current code is below. I don't mind if this is adjusted or its completely re-written, whatever is easier so long as it alerts for past dates, today or tomorrow and Sundays.
function ff_date_validation(element, message)
{
var data = element.value ;
data = data.replace("/","-");
var dmy = data.split("-");
if (dmy.length != 3)
{
return ( message == '' ) ? message : " Please tell us which day you'd like the service to take place " ;
}
var vDate = new Date(dmy[2] - 0, dmy[1] -1, dmy[0] - 0,0,0,0,0);
//alert(vDate);
var today = new Date();
//alert(today);
if(vDate.getTime() 1)
{
return "Unfortunately we cannot take bookings for today or tomorrow.";
}
}
else
{
return "The date cannot be in the past.";
}
}
if ((vDate.getDay() == 0) || (vDate.getDay() == 7))
{
return "Unfortunately we cannot take bookings on Sundays";
}
return '';
} // ff_date_validation

Richard P.
100% (90)Projects Completed
88
Freelancers worked with
48
Projects awarded
65%
Last project
19 Feb 2025
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies