Skip to content

Instantly share code, notes, and snippets.

@crynobone
Created March 10, 2011 21:24
Show Gist options
  • Save crynobone/864959 to your computer and use it in GitHub Desktop.
Save crynobone/864959 to your computer and use it in GitHub Desktop.
Malaysia Indentification Card Number to Birthdate
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment