//身份证校验
function IdentityCodeValid(code:string) {
  let m = /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/
  return m.test(code)
}

// 手机号校验
function isPoneAvailable(poneInput:string) {
  var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  if (!myreg.test(poneInput)) {
    return false;
  } else {
    return true;
  }
}
// 身份证号获取出生年月日
function getBirthdatByIdNo(iIdNo:string) {
  var tmpStr = "";
  iIdNo = iIdNo.replace(/^\s+|\s+$/g, "");

  if (iIdNo.length == 15) {
    tmpStr = iIdNo.substring(6, 12);
    tmpStr = "19" + tmpStr;
    tmpStr = tmpStr.substring(0, 4) + "/" + tmpStr.substring(4, 6) + "/" + tmpStr.substring(6)
  } else {
    tmpStr = iIdNo.substring(6, 14);
    tmpStr = tmpStr.substring(0, 4) + "/" + tmpStr.substring(4, 6) + "/" + tmpStr.substring(6)
  }
  return tmpStr;
}

// 获取性别
function getSex(idcard:string) {
  let sex = ''
  if (parseInt(idcard.substr(16, 1)) % 2 == 1) {
    sex = '男'
  } else {
    sex = '女'
  }
  return sex
}

// 微信号校验
function authCode(str:string){
  let length = str.replace(/\s/g,"").length
  return length
}
export const fun = {
  IdentityCodeValid,
  isPoneAvailable,
  getBirthdatByIdNo,
  getSex,
  authCode
}