var chkdate=document.getElementById('date');
var dateformat=/^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01]){2}/;
if(!dateformat.test(chkdate.value))
{
alert("Please format the date in yyyy-mm-dd format.");
return false;
}
and the html:
<form name="test" action="" onsubmit="return validateForm()" method="post">
Name: <input type="text" placeholder="First Last" name="name" id="name"><br />
Date: <input type="text" placeholder="yyyy-mm-dd" name="date" id="date"><br />
Number: <input type="integer" placeholder="Any integer/decimal" name="number" id="number"><br /><br />
<input type="submit" value="Submit">
The validation works in the format yyyy-mm, however the day allows you to enter any number of numbers at the end. I.e 2013-06-14444444444 would get passed through. I want to restrict it purely to JUST yyyy-mm-dd. How would I go above achieving this?