I'm currently working on a birthday validation form using JavaScript and I'm facing some issues. For instance, the date 40/40/2012 should be considered invalid but no alert is being triggered.
Here is the JavaScript code:
function validateBirthday(form_element) {
var birthday = form_element.birthday.value;
if ( !/\d{2}\/\d{2}\/\d{4}/.test(form_element.birthday.value) )
{
alert("This field is required. Please enter a valid date in the format mm/dd/yyyy!");
return false;
}
return true;
}
And here is the HTML form code:
<form onsubmit="return validateBirthday(this)">
Birthday:<input type="text" name="birthday" /><br />
<input type="submit" value="Submit" />
</form>