次のようなものが必要だと思います:http://jsfiddle.net/hqNxW/1/
そしてコード...
JavaScript
var output = document.getElementById('messageOutput');
document.getElementById('validate').onclick = function () {
var value = document.getElementById('date').value;
if (!validateDate(value)) {
notify('Invalid date format');
} else {
if (!validateDateRange(value)) {
notify('The date should be after today but not more than 29 days!');
} else {
notify('Valid date');
}
}
}
function notify(msg) {
output.innerHTML = msg;
}
function validateDate(date) {
return (/^\d{2}-\d{2}-\d{4}$/).test(date);
}
function validateDateRange(inputDate) {
var now = new Date(),
after30Days = new Date().setDate(now.getDate() + 30)
date = new Date(inputDate);
return date > now && date < after30Days;
}
HTML
<input type="text" id="date" /> <button id="validate">Validate</button>
<div id="messageOutput">Enter a date in the following format: mm-dd-yyyy</div>