Our Blog

Universal date validation

function checkDate( strArgs, isMMDDYYYY )
{
/* verifica se strArgs e uma string de data valida
se estiver valida retorna TRUE senao retorna FALSE
strArgs – obrigatorio – data no formato ddmmaaaa ou mmddaaaa
isMMDDYYYY – opcional – true para datas no formato mmddaaa
*/

isMMDDYYYY = isMMDDYYYY == undefined ? false : true;
strDD = isMMDDYYYY ? strArgs.substring(3, 5) : strArgs.substring(0, 2)
strMMM = isMMDDYYYY ? strArgs.substring(0, 2) : strArgs.substring(3, 5)
strYYYY = strArgs.substring(6, 10);

switch ( parseInt(strMMM) ) {
case 1 : strMMM=”Jan”; break;
case 2 : strMMM=”Feb”; break;
case 3 : strMMM=”Mar”; break;
case 4 : strMMM=”Apr”; break;
case 5 : strMMM=”May”; break;
case 6 : strMMM=”Jun”; break;
case 7 : strMMM=”Jul”; break;
case 8 : strMMM=”Aug”; break;
case 9 : strMMM=”Sep”; break;
case 10 : strMMM=”Oct”; break;
case 11 : strMMM=”Nov”; break;
case 12 : strMMM=”Dec”; break;
default : strMMM= “Invalid”
}

var strDate = strDD + ‘ ‘ + strMMM + ‘ ‘ + strYYYY;
var datDate = new Date(strDate);
var datDate_string = datDate.toGMTString();
var arrDate = datDate_string.split(‘ ‘);

value = (arrDate[2] != strMMM) ? false : true
return value;
}

Bruno Grange

A passionate by software and a business enthusiast. Check out more about me at http://www.brunogrange.com