Date Validation on Text Field
Here comes the code that checks for the date entry. This event can be called on either KEY DOWN or ONBLUR event of the text box
function ChkDtG(item)
{
var vDd2Digs;
var vMn2Digs;
var vYr4Digs;
var vChkDt = item.value;
vDd2Digs = vChkDt.substr(0,2);
vMn2Digs = vChkDt.substr(3,2);
vYr4Digs = vChkDt.substr(6,4);
var vTf = true;
if(vDd2Digs == '00' vMn2Digs == '00' vYr4Digs == '0000' vMn2Digs > 12 vDd2Digs > 31 vYr4Digs < vtf =" false;}" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="">31){vTf=false;}if(vMn2Digs == 2 vMn2Digs == 4 vMn2Digs == 6 vMn2Digs == 9 vMn2Digs == 11)
{if(vDd2Digs>30){vTf=false;}}}
if(vMn2Digs == 2)
{var vMdRe = (vYr4Digs % 4);if(vMdRe == 0){if(vDd2Digs > 29){vTf = false;}}else{if(vDd2Digs > 28){vTf = false}}}
if(vTf == false){alert(item.value + ' is invalid date ');item.value = "";item.focus();return false;}
}
function ChkDtG(item)
{
var vDd2Digs;
var vMn2Digs;
var vYr4Digs;
var vChkDt = item.value;
vDd2Digs = vChkDt.substr(0,2);
vMn2Digs = vChkDt.substr(3,2);
vYr4Digs = vChkDt.substr(6,4);
var vTf = true;
if(vDd2Digs == '00' vMn2Digs == '00' vYr4Digs == '0000' vMn2Digs > 12 vDd2Digs > 31 vYr4Digs < vtf =" false;}" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="" vmn2digs ="="">31){vTf=false;}if(vMn2Digs == 2 vMn2Digs == 4 vMn2Digs == 6 vMn2Digs == 9 vMn2Digs == 11)
{if(vDd2Digs>30){vTf=false;}}}
if(vMn2Digs == 2)
{var vMdRe = (vYr4Digs % 4);if(vMdRe == 0){if(vDd2Digs > 29){vTf = false;}}else{if(vDd2Digs > 28){vTf = false}}}
if(vTf == false){alert(item.value + ' is invalid date ');item.value = "";item.focus();return false;}
}
Comments