Skip to content

Instantly share code, notes, and snippets.

@crynobone
Created March 10, 2011 21:24

Revisions

  1. crynobone created this gist Mar 10, 2011.
    21 changes: 21 additions & 0 deletions Birthdate Parser.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    var ic = '090303086521';

    if(ic.match(/^(\d{2})(\d{2})(\d{2})-?\d{2}-?\d{4}$/)) {
    var year = RegExp.$1;
    var month = RegExp.$2;
    var day = RegExp.$3;
    console.log(year, month, day);

    var now = new Date().getFullYear().toString();

    var decade = now.substr(0, 2);
    if (now.substr(2,2) > year) {
    year = parseInt(decade.concat(year.toString()), 10);
    }

    var date = new Date(year, (month - 1), day, 0, 0, 0, 0);
    console.log(date);
    }
    else {
    // not a proper IC format
    }