Link to home
Start Free TrialLog in
Avatar of mfinocc
mfinocc

asked on

Frontpage - formatting a textbox for date entry mm/dd/yyyy

Does anyone know how to set up the textbox so that a date can only be entered in mm/dd/yyyy? A calendar date selector could work too id you have the code.

Thanks
Avatar of James Murrell
James Murrell
Flag of United Kingdom of Great Britain and Northern Ireland image

try this just need to change bottom part as for uk
try this simple javascript
 
function dateValidation()
{
 
var obj = document.getElementById("<%=txtDate.ClientID%>");
var day = obj.value.split("/")[0];
 
var month = obj.value.split("/")[1];
var year = obj.value.split("/")[2];
 
if ((day<1 || day >31) || (month<1&&month>12)&&(year.length != 4))
{
 
alert("Invalid Format");return false;
}
 
else
 
{
 
var dt = new Date(year, month-1, day);
var today = new Date();
 
if((dt.getDate() != day) || (dt.getMonth() != month-1) || (dt.getFullYear()!=year) || (dt>today))
{
 
alert("Invalid Date");return false;
}
 
}
 
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of rcmb
rcmb

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mfinocc
mfinocc

ASKER

Thanks!