功能簡單介紹:針對一串身份證字串(string)的處理:
1. 驗證身份證的正確性
2. 提取出生年月日
3. 提取性別
4. 把15位的身份證號碼轉成18位
直接上**:
#pragma once
#include using namespace std;
bool isvalidcitizenno18(string& strcitizenno)
; char valid_num = ;
int nsum = 0;
int nmode = 0;
int nlen = strcitizenno.size();
if (nlen == 18)
return false;
}bool cid15tocid18(string& strcid15, string& strresult)
; char valid_num = ;
int nsum = 0;
int nmode = 0;
strresult = strcid15;
strresult.resize(18);
for (int i = 16; i > 7; --i)
strresult[i] = strresult[i - 2];
strresult[6] = '1';
strresult[7] = '9';
for (int i = 0; i < 17; ++i)
nsum += (strresult[i] - '0') * weight[i];
nmode = nsum % 11;
strresult[17] = valid_num[nmode];
return true;
}bool isleapyear(int nyear)
bool checkbirthdayvalid(int nyear, int nmonth, int nday)
else if (nday > 28)
return false;
} else if (4 == nmonth || 6 == nmonth || 9 == nmonth || 11 == nmonth)
return true;
}bool isvalidcitizenno(string& strcitizenno)
if (nlen == 15)
else if (!isvalidcitizenno18(strcitizenno))
return false;
// check birthday valid.
string stryear, strmonth, strday;
stryear += strcitizenno[6];
stryear += strcitizenno[7];
stryear += strcitizenno[8];
stryear += strcitizenno[9];
strmonth += strcitizenno[10];
strmonth += strcitizenno[11];
strday += strcitizenno[12];
strday += strcitizenno[13];
int nyear = atoi(stryear.c_str());
int nmonth = atoi(strmonth.c_str());
int nday = atoi(strday.c_str());
if (!checkbirthdayvalid(nyear, nmonth, nday))
return false;
return true;
}bool getcitizennoinfo(string& strcitizenno, int& nyear, int& nmonth, int& nday, bool ismale)
讀取身份證資訊 php 讀取身份證資訊
namespace class identitycardservice 獲取位址 public function get addr id 根據身份證號,自動返回對應的星座 param cid return string public function getstarsign cid elseif m...
身份證相關操作
class idcardaction extends action elseif month 2 day 19 month 3 day 20 elseif month 3 day 20 month 4 day 19 elseif month 4 day 20 month 5 day 20 elsei...
實名驗證身份證資訊
php函式實現了乙個實名驗證身份證的資訊 如下 實名認證身份證號資訊 public function iscreditno vstr 函式名 iscreditno,引數 vstr,表示傳入的身份證號碼 xx d d vstr return false 如果出現17個數字加乙個 x 或 x 以及乙個數...