判斷身份證 銀行卡 手機號等

2021-08-31 23:57:38 字數 4481 閱讀 1814

//判斷手機號

+ (bool)checkphone:(nsstring *)phonenumber

/*** 手機號碼:

* 13[0-9], 14[5,7], 15[0, 1, 2, 3, 5, 6, 7, 8, 9], 17[6, 7, 8], 18[0-9], 170[0-9]

* 移動號段: 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705

* 聯通號段: 130,131,132,155,156,185,186,145,176,1709

* 電訊號段: 133,153,180,181,189,177,1700

*/nsstring *mobile = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[0678])\\d$";

/*** 中國移動:china mobile

* 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705

*/nsstring *cm = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\\d$)|(^1705\\d$)";

/*** 中國聯通:china unicom

* 130,131,132,155,156,185,186,145,176,1709

*/nsstring *cu = @"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\\d$)|(^1709\\d$)";

/*** 中國電信:china telecom

* 133,153,180,181,189,177,1700

*/nsstring *ct = @"(^1(33|53|77|8[019])\\d$)|(^1700\\d$)";

/**25 * 大陸地區固話及小靈通

26 * 區號:010,020,021,022,023,024,025,027,028,029

27 * 號碼:七位或八位

28 */

// nsstring * phs = @"^(0[0-9])\\d$|^(0[0-9](\\d))$";

nspredicate *regextestmobile = [nspredicate predicatewithformat:@"self matches %@", mobile];

nspredicate *regextestcm = [nspredicate predicatewithformat:@"self matches %@", cm];

nspredicate *regextestcu = [nspredicate predicatewithformat:@"self matches %@", cu];

nspredicate *regextestct = [nspredicate predicatewithformat:@"self matches %@", ct];

if (([regextestmobile evaluatewithobject:phonenumber] == yes)

|| ([regextestcm evaluatewithobject:phonenumber] == yes)

|| ([regextestct evaluatewithobject:phonenumber] == yes)

|| ([regextestcu evaluatewithobject:phonenumber] == yes))

return no;

}#pragma mark - 演算法相關

// //精確的身份證號碼有效性檢測

+ (bool)accurateverifyidcardnumber:(nsstring *)identitystring

[1-9]\\d((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d([0-9]|x)$";

// nsstring *regex = @"^(^[1-9]\\d((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d$)|(^[1-9]\\d[1-9]\\d((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d)|\\d[xx])$)$";

nspredicate *identitystringpredicate = [nspredicate predicatewithformat:@"self matches %@",regex];

//如果通過該驗證,說明身份證格式正確,但準確性還需計算

if(![identitystringpredicate evaluatewithobject:identitystring]) return no;

//** 開始進行校驗 *//

//將前17位加權因子儲存在陣列裡

nsarray *idcardwiarray = @[@"7", @"9", @"10", @"5", @"8", @"4", @"2", @"1", @"6", @"3", @"7", @"9", @"10", @"5", @"8", @"4", @"2"];

//這是除以11後,可能產生的11位餘數、驗證碼,也儲存成陣列

nsarray *idcardyarray = @[@"1", @"0", @"10", @"9", @"8", @"7", @"6", @"5", @"4", @"3", @"2"];

//用來儲存前17位各自乖以加權因子後的總和

nsinteger idcardwisum = 0;

for(int i = 0;i < 17;i++)

//計算出校驗碼所在陣列的位置

nsinteger idcardmod=idcardwisum%11;

//得到最後一位身份證號碼

nsstring *idcardlast= [identitystring substringwithrange:nsmakerange(17, 1)];

//如果等於2,則說明校驗碼是10,身份證號碼最後一位應該是x

if(idcardmod==2)

}else

}return yes;

}#pragma mark 銀行卡驗證有效性

/** 銀行卡號有效性問題luhn演算法

254 * 現行 16 位銀聯卡現行卡號開頭 6 位是 622126~622925 之間的,7 到 15 位是銀行自定義的,

255 * 可能是發卡分行,發卡網點,發卡序號,第 16 位是校驗碼。

256 * 16 位卡號校驗位採用 luhm 校驗方法計算:

257 * 1,將未帶校驗位的 15 位卡號從右依次編號 1 到 15,位於奇數字型大小上的數字乘以 2

258 * 2,將奇位乘積的個十位全部相加,再加上所有偶數字上的數字

259 * 3,將加法和加上校驗位能被 10 整除。

260 */

+ (bool)bankcardluhmcheck:(nsstring * )bankcadnumber

nsmutablearray * arroddnum = [[nsmutablearray alloc] initwithcapacity:0];//奇數字*2的積 < 9

nsmutablearray * arroddnum2 = [[nsmutablearray alloc] initwithcapacity:0];//奇數字*2的積 > 9

nsmutablearray * arrevennum = [[nsmutablearray alloc] initwithcapacity:0];//偶數字陣列

for (int i=0; i< forwarddescarr.count; i++) elseelse}}

__block nsinteger sumoddnumtotal = 0;

[arroddnum enumerateobjectsusingblock:^(nsnumber * obj, nsuinteger idx, bool *stop) ];

__block nsinteger sumoddnum2total = 0;

[arroddnum2 enumerateobjectsusingblock:^(nsnumber * obj, nsuinteger idx, bool *stop) ];

__block nsinteger sumevennumtotal =0 ;

[arrevennum enumerateobjectsusingblock:^(nsnumber * obj, nsuinteger idx, bool *stop) ];

nsinteger lastnumber = [lastnum integervalue];

nsinteger luhmtotal = lastnumber + sumevennumtotal + sumoddnum2total + sumoddnumtotal;

return (luhmtotal%10 ==0)?yes:no;

}

身份證 手機號 郵箱 銀行卡 企業稅號等正則校驗

身份證號正則校驗 前6位 第一位1到9範圍 後5位 數字 1 9 d 年份4位 開頭兩位 18 or 19 or 20 後面2位數字 18 19 20 d 月份2位 1開頭 第二位為0到2 或者 0開頭 第二位1到9 1 0 2 0 1 9 日期2位 第一位0到2的範圍,第二位1到9的返回 加上10...

身份證,銀行卡丟失後

1.立馬打 到銀行,對銀行卡進行口頭掛失,對銀行卡進行凍結,一般會有幾天的凍結期,如廣發是5天,工商是15天。2.去派出所報案,立乙個案,這一步基本不會起到什麼作用,因為派出所每天會接到n多這樣的案子,在他們看來,這事太小了。但還是得立一下,其會開乙個立案回執單。3.辦臨時身份證,由於臨時身份證的辦...

身份證 銀行卡識別方案

b.月介面呼叫總量 0 呼叫量 1000 1000 呼叫量 1萬 1萬 呼叫量 10萬 10萬以上 身份證識別 免費0.2元 次 0.12元 次 0.08元 次 銀行卡免費 0.2元 次 0.15元 次 0.08元 次 月介面呼叫總量 0 呼叫量 15000 500次 日 0 呼叫量 5萬 5萬 呼...