iOS身份证控制和手机号设置 和 十六进制的颜色转换为UIColor

#import "Global.h"

#import "UIToastView.h"

#import "MBProgressHUD.h"



#import "CommonCrypto/CommonDigest.h"


static Global *sharedInstance;

static NSString * HUDShowContent;


//

@interface Global()

<MBProgressHUDDelegate>

{

    MBProgressHUD * _myHUD;

}

@property (nonatomic,strong) MBProgressHUD * myHUD;


@end


//

@implementation Global

//@synthesize userInfo=_userInfo;

@synthesize loginedUserModel=_loginedUserModel;

@synthesize myHUD=_myHUD;


+(Global *)sharedInstance{

    if(!sharedInstance){

        sharedInstance = [[Global alloc] init];

    }

   return sharedInstance;

}


+ (void)showAlertWithTitle:(NSString *)titlt message:(NSString *)message

{

    NSString * errMsg = message;

    

    if ([message hasSuffix:@"Authentication needed}"]) {

        errMsg = AuthenticationNeeded;}

    else if ([message hasSuffix:@"The request timed out}"]) {

        errMsg = TheRequestTimedOut;}

    else if ([message hasSuffix:@"The request was cancelled}"]) {

        errMsg = TheRequestWasCancelled;}

    else if ([message hasSuffix:@"Unable to create request (bad url?)}"]) {

        errMsg = UnableToCreateRequestBadUrl;}

    else if ([message hasSuffix:@"The request failed because it redirected too many times}"]) {errMsg = TheRequestFailedBecauseItRedirectedTooManyTimes;}

    else if ([message hasSuffix:@"A connection failure occurred}"]) {

        errMsg = AConnectionFailureOccurred;}

    

    UIAlertView * alert = [[UIAlertView alloc]initWithTitle:titlt message:errMsg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

    [alert show];

}


+ (void)showToastViewWithText:(NSString *)text

{

    UIToastView * toastView = [UIToastView makeText:text duration:1.5 gravity:UIToastGravityCenter];

    [toastView show];

}


#pragma mark - HUD


+ (NSString *)getHUDShowContent{

    return HUDShowContent;

}


+ (void)setHUDShowContent:(NSString *)content

{

    HUDShowContent = content;

}


- (void)showMyHUD

{

    if (self.myHUD != nil) { return;}

    

    UIView * uiView = [UIApplication sharedApplication].delegate.window;

    self.myHUD = [[MBProgressHUD alloc] initWithView:uiView];

    [uiView addSubview:self.myHUD];

    self.myHUD.dimBackground = YES;

//    _HUD.labelText = [Global getHUDShowContent];

    self.myHUD.labelText = @"Loading...";

    [self.myHUD show:YES];

//    [Global setIsHUDShowwing:YES];

}


- (void)hideMyHUD

{

    //操作执行完后取消对话框

    [self.myHUD hide:YES];

    [self.myHUD removeFromSuperview];

    self.myHUD = nil;

}


#pragma mark - 生成一个GUID UUID


+ (NSString *)generateAGuid

{

    CFUUIDRef uuid_ref = CFUUIDCreate(NULL);

    CFStringRef uuid_string_ref= CFUUIDCreateString(NULL, uuid_ref);

    CFRelease(uuid_ref);

    NSString *uuid = [NSString stringWithString:(__bridge NSString*)uuid_string_ref];

    CFRelease(uuid_string_ref);

    return uuid;

}


/***********************************************************/


#pragma mark - 颜色转换 IOS中十六进制的颜色转换为UIColor


+ (UIColor *)colorWithHexString: (NSString *)color

{

    NSString *cString = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];

    

    // String should be 6 or 8 characters

    if ([cString length] < 6) {

        return [UIColor clearColor];

    }

    

    // strip 0X if it appears

    if ([cString hasPrefix:@"0X"])

        cString = [cString substringFromIndex:2];

    if ([cString hasPrefix:@"#"])

        cString = [cString substringFromIndex:1];

    if ([cString length] != 6)

        return [UIColor clearColor];

    

    // Separate into r, g, b substrings

    NSRange range;

    range.location = 0;

    range.length = 2;

    

    //r

    NSString *rString = [cString substringWithRange:range];

    

    //g

    range.location = 2;

    NSString *gString = [cString substringWithRange:range];

    

    //b

    range.location = 4;

    NSString *bString = [cString substringWithRange:range];

    

    // Scan values

    unsigned int r, g, b;

    [[NSScanner scannerWithString:rString] scanHexInt:&r];

    [[NSScanner scannerWithString:gString] scanHexInt:&g];

    [[NSScanner scannerWithString:bString] scanHexInt:&b];

    

    return [UIColor colorWithRed:((float) r / 255.0f) green:((float) g / 255.0f) blue:((float) b / 255.0f) alpha:1.0f];

}


+ (UIFont *)fontWithPX:(CGFloat)px

{

    CGFloat fontSize = px*72/96;

    return [UIFont systemFontOfSize:fontSize];

    

}


/***********************************************************/


//验证手机号码是否正确(全面):

+ (BOOL)isMobileNumberRightful:(NSString *)mobileNum

{

    if (mobileNum.length<=0) {

        return NO;

    }

    

    NSString * phoneRegex = @"^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$";

    NSPredicate * phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];

    BOOL isMatch = [phoneTest evaluateWithObject:mobileNum];

    return isMatch;

}


//验证手机号码是否正确(简单):

+(BOOL)isTelNumberRightFul:(NSString*)tel

{

    if (tel.length<=0) {

        return NO;

    }

    

    NSString * phoneRegex = @"^[0-9]{3,4}[-][0-9]{7,8}([-][0-9]{3,4})?$";

    NSPredicate * phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];

    BOOL isMatch = [phoneTest evaluateWithObject:tel];

    return isMatch;

}


验证身份证号是否正确(简单):

//+ (BOOL)isIdentityCardRightful: (NSString *)idCard

//{

//    if (idCard.length <= 0) {

//        return NO;

//    }

//    

//    NSString * regex = @"^(\\d{14}|\\d{17})(\\d|[xX])$";

//    NSPredicate * idCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];

//    BOOL isMatch = [idCardPredicate evaluateWithObject:idCard];

//    return isMatch;

//}


// 身份证识别(全面)

+(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;

}



@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值