iOS Development ID Number check

Source: Internet
Author: User

//

Card.h

Thcstore

//

Created by Mac on 15/7/15.

Copyright (c) 2015 Mac. All rights reserved.

//

#import <Foundation/Foundation.h>

@interface Card:nsobject

+ (BOOL) Validateidcardnumber: (NSString *) value;

@end

//

Card.m

Thcstore

//

Created by Mac on 15/7/15.

Copyright (c) 2015 Mac. All rights reserved.

//

#import "Card.h"

@implementation Card

+ (BOOL) Validateidcardnumber: (NSString *) value {

Value = [value Stringbytrimmingcharactersinset:[nscharacterset Whitespaceandnewlinecharacterset]];

int length = 0;

if (!value) {

return NO;

}else {

length = Value.length;

if (length!=15 && length!=18) {

return NO;

}

}

Province code

Nsarray *areasarray [Email protected][@ "11", @ "12", @ "13", @ "14", @ "15", @ "21", @ "22", @ "23", @ "31", @ "32", @ "33", @ "34", @ " 35 ", @" 36 ", @" 37 ", @" 41 ", @" 42 ", @" 43 ", @" 44 ", @" 45 ", @" 46 ", @" 50 ", @" 51 ", @" 52 ", @" 53 ", @" 54 ", @" 61 ", @" 62 ", @" 63 ", @" 64 ", @" 65 ", @" 71 ", @" 81 ", @" 82 ", @" 91 "];

NSString *valuestart2 = [value substringtoindex:2];

BOOL Areaflag =no;

For (NSString *areacode in Areasarray) {

if ([AreaCode Isequaltostring:valuestart2]) {

Areaflag =yes;

Break

}

}

if (!areaflag) {

return false;

}

Nsregularexpression *regularexpression;

Nsuinteger Numberofmatch;

int year = 0;

Switch (length) {

Case 15:

Year = [value Substringwithrange:nsmakerange (6,2)].intvalue +1900;

if (Year%4 ==0 | | (Year%100 ==0 && year%4 ==0)) {

RegularExpression = [[Nsregularexpression alloc]initwithpattern:@ "^[1-9][0-9]{5}[0-9]{2} ((01|03|05|07|08|10|12) (0 [1-9]| [1-2] [0-9]|3[0-1]) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30] |02 (0[1-9]|[ 1-2][0-9])) [0-9]{3}$]

Options:nsregularexpressioncaseinsensitive

error:nil];//testing the legality of birth date

}else {

RegularExpression = [[Nsregularexpression alloc]initwithpattern:@ "^[1-9][0-9]{5}[0-9]{2} ((01|03|05|07|08|10|12) (0 [1-9]| [1-2] [0-9]|3[0-1]) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30) |02 (0[1-9]|1[0-9]|2[0-8])) [0-9]{3}$]

Options:nsregularexpressioncaseinsensitive

error:nil];//testing the legality of birth date

}

Numberofmatch = [RegularExpression numberofmatchesinstring:value

Options:nsmatchingreportprogress

Range:nsmakerange (0, value.length)];

[RegularExpression release];

if (Numberofmatch >0) {

return YES;

}else {

return NO;

}

Case 18:

Year = [value Substringwithrange:nsmakerange (6,4)].intvalue;

if (Year%4 ==0 | | (Year%100 ==0 && year%4 ==0)) {

RegularExpression = [[Nsregularexpression alloc]initwithpattern:@ "^[1-9][0-9]{5}19[0-9]{2} ((01|03|05|07|08|10|12) (0[1-9]| [1-2] [0-9]|3[0-1]) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30] |02 (0[1-9]|[ 1-2][0-9])) [0-9]{3}[0-9xx]$]

Options:nsregularexpressioncaseinsensitive

error:nil];//testing the legality of birth date

}else {

RegularExpression = [[Nsregularexpression alloc]initwithpattern:@ "^[1-9][0-9]{5}19[0-9]{2} ((01|03|05|07|08|10|12) (0[1-9]| [1-2] [0-9]|3[0-1]) | (04|06|09|11) (0[1-9]| [1-2] [0-9]|30) |02 (0[1-9]|1[0-9]|2[0-8])) [0-9]{3}[0-9xx]$]

Options:nsregularexpressioncaseinsensitive

error:nil];//testing the legality of birth date

}

Numberofmatch = [RegularExpression numberofmatchesinstring:value

Options:nsmatchingreportprogress

Range:nsmakerange (0, value.length)];

if (Numberofmatch >0) {

                int S = ([Value substringwithrange:nsmakerange (0,1)].intvalue + [v] Alue Substringwithrange:nsmakerange (10,1)].intvalue) *7 + ([value substringwithrange:nsmakerange]].intValue + [ Value Substringwithrange:nsmakerange (11,1)].intvalue) *9 + ([value Substringwithrange:nsmakerange (2,1)].intValue + [ Value Substringwithrange:nsmakerange (12,1)].intvalue) *10 + ([value Substringwithrange:nsmakerange (3,1)].intValue + [ Value Substringwithrange:nsmakerange (13,1)].intvalue) + ([value Substringwithrange:nsmakerange (4,1)].intValue + [ Value Substringwithrange:nsmakerange (14,1)].intvalue) *8 + ([value Substringwithrange:nsmakerange (5,1)].intValue + [ Value Substringwithrange:nsmakerange (15,1)].intvalue) + ([value Substringwithrange:nsmakerange (6,1)].intValue + [ Value Substringwithrange:nsmakerange (16,1)].intvalue) * + [value substringwithrange:nsmakerange (7,1)].intValue * + [ Value Substringwithrange:nsmakerange (8,1)].intvalue *6 + [valueSubstringwithrange:nsmakerange (9,1)].intvalue;

int Y = S% 11;

NSString *m [email protected] "F";

NSString *jym [email protected] "10x98765432";

M = [Jym substringwithrange:nsmakerange (y,1)];//determine check digit

if ([M isequaltostring:[value Substringwithrange:nsmakerange (17,1)]]) {

return yes;//check digit for detection ID

}else {

return NO;

}

}else {

return NO;

}

Default

return false;

}

}

@end

iOS Development ID Number check

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.