[script type="text/javascript"]
function CalculateAge(birthday)
{
var re=/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/;
if (birthday.value != '') {
If (re.test(birthday.value)) Then
{
birthdayDate = new Date(birthday.value);
dateNow = new Date();
var years = dateNow.getFullYear() - birthdayDate.getFullYear();
var months=dateNow.getMonth()-birthdayDate.getMonth();
var days=dateNow.getDate()-birthdayDate.getDate();
if (isNaN(years)) {
document.getElementById('lblAge').innerHTML = '';
document.getElementById('lblError').innerHTML = 'Input date is incorrect!';
return false;
}
else {
document.getElementById('lblError').innerHTML = '';
document.getElementById('lblAge').innerHTML = years +' Years ' +months +' months '+days +' days';
}
}
else
{
document.getElementById('lblError').innerHTML = 'Date must be mm/dd/yyyy format';
return false;
}}}
[/script]
[/head>
[body>
[form id="form1" runat="server">
[div>
Date of Birth :
[span style="color: Red">
[asp:Label ID="lblError" runat="server">
[br />
Age : [span id="lblAge">
[/div>
[/form>
[/body>
[/html>
No comments:
Post a Comment