js intercepts the birthday in the ID number

CODE:
function getBirthdayFromIdCard(idCard) {
  var birthday = "";
  if(idCard != null && idCard != ""){
	  if(idCard.length == 15){
		  birthday = "19"+idCard.substr(6,6);
	  } else if(idCard.length == 18){
		  birthday = idCard.substr(6,8);
	  }
  
	  birthday = birthday.replace(/(.{4})(.{2})/,"$1-$2-");
  }
  return birthday;
}


Demo:
var idcard = "425125198808083000";
getBirthdayFromIdCard(idcard );


Result: 1988-08-08


Reference address:
http://qiaolevip.iteye.com/blog/1946057




Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326716190&siteId=291194637