I have this Calendar Control I am using. A user can select any date from the calendar. I need to validate the dates like Saturday and Sundays and 1/1 and 1/25. If they select these days I need to show them a Popup message if it’s not a valid date.
Share
Try this:
This is set up with a
changeevent. Your event may be different.It get’s the value of the input:
$(this).val()Creates a new
Dateobject from it:new Date($(this).val())Then gets the day number:
.getDay()which returns a value from 0 to 6 with 0 being Sunday and 6 being Saturday.Then you just test for 0 or 6.
Live Example: http://jsfiddle.net/UwcLf/
EDIT: Courtesy of Nick Craver, you can disable specific days if you have no need to run alternate code for weekend selections.
From Nick’s linked answer: Disable specific days of the week on jQuery UI datepicker
Updated Example: http://jsfiddle.net/UwcLf/1/
Added array for disabled days: http://jsfiddle.net/UwcLf/3/