Using javascript I need to validate a form field containing a date in the format: 21/04/2010. The date must be a weekday. Is it possible to create a regular expression for this or is there another, better way to do it?
Regex is clearly the wrong tool. Use Date.getDay():
var d = new Date();
var parts = dateStr.split("/");
// Date of month is 0-indexed.
var d = new Date(parts[2], parts[1] - 1, parts[0]);
var day = d.getDay();
if(day == 0 || day == 6)
{
// weekend
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With