-
-
Save afiqiqmal/1b5f31c5ee9d8efdc3225eeb421b411b to your computer and use it in GitHub Desktop.
Malaysia Indentification Card Number to Birthdate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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