• iOS


    - (BOOL)checkIdentityCardNo:(NSString*)cardNo

    {

        if (cardNo.length != 18) {

            return  NO;

        }

        NSArray* codeArray = [NSArray arrayWithObjects:@"7",@"9",@"10",@"5",@"8",@"4",@"2",@"1",@"6",@"3",@"7",@"9",@"10",@"5",@"8",@"4",@"2", nil];

        NSDictionary* checkCodeDic = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1",@"0",@"X",@"9",@"8",@"7",@"6",@"5",@"4",@"3",@"2", nil]  forKeys:[NSArray arrayWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10", nil]];

        

        NSScanner* scan = [NSScanner scannerWithString:[cardNo substringToIndex:17]];

        

        int val;

        BOOL isNum = [scan scanInt:&val] && [scan isAtEnd];

        if (!isNum) {

            return NO;

        }

        int sumValue = 0;

        

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

            sumValue+=[[cardNo substringWithRange:NSMakeRange(i , 1) ] intValue]* [[codeArray objectAtIndex:i] intValue];

        }

        

        NSString* strlast = [checkCodeDic objectForKey:[NSString stringWithFormat:@"%d",sumValue%11]];

        

        if ([strlast isEqualToString: [[cardNo substringWithRange:NSMakeRange(17, 1)]uppercaseString]]) {

            return YES;

        }

        return  NO;

    }

    - (BOOL)isMobileNumber:(NSString *)mobileNumString

    {

        NSString *pattern = @"^1+[3578]+\d{9}";

        NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];

        BOOL isMatch = [pred evaluateWithObject:mobileNumString];

        return isMatch;

    }

  • 相关阅读:
    Servlet设置Cookie无效
    IOS即时通讯XMPP搭建openfire服务器
    IOS之富文本编辑
    unittest单元测试框架总结
    杀死future处理的阻塞线程
    APP的UI设计原则
    如何降低一个程序的耦合性
    Hyperopt中文文档导读
    Hyperopt中文文档导读
    AdaBoost算法特性
  • 原文地址:https://www.cnblogs.com/Cheetah-yang/p/4843744.html
Copyright © 2020-2023  润新知