/**
* @param {string} date
* @returns {Date}
*/
function parseDate(date) {
var match = date.match(/\d+/g);
if (match !== null && match.length === 3) {
var year = Number((match[0].length > 2 ? match.reverse() : match)[2]);
var month = match[1] - 1;
var day = Number(match[0]);
var date_ = new Date(year, month, day);
if (date_.getFullYear() === year && date_.getMonth() === month && date_.getDate() === day) {
return date_;
}
}
return new Date(NaN);
}
/**
* @see [url]http://javascript.ru/forum/misc/38107-vychislenie-vozrasta.html[/url]
*
* @param {Date|int} bd
* @returns {int}
*/
function birthDateToAge(bd) {
bd = new Date(bd);
var now = new Date();
return now.getFullYear() - bd.getFullYear() - (now.setFullYear(1972) < bd.setFullYear(1972) ? 1 : 0);
}
alert(birthDateToAge(parseDate('19.01.1988')));