Testing whether date entered into a text box is a date of format 'YYYY-mm-dd'

Testing whether date entered into a text box is a date of format 'YYYY-mm-dd'


var to_date = $("#edit-to-date").val();
if(/[0-9]{4}-[0-9]{2}-[0-9]{2}/.test(to_date))
{
alert("hello");
}


test() returns true if the date matches the format. If it doesn't match the date it returns false.

Comments