iOS判断字符串是否为手机号,iOS判断字符串是是否为字符串,iOS判断字符串是否为纯数字


#pragma 正则匹配手机号

+ (BOOL)isPhoneNumber:(NSString *)str

 

{

    if ([str length] == 0) {

        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示"message:@"请输入手机号码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

        [alert show];

        return NO;

    }

    NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";

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

    BOOL isMatch = [pred evaluateWithObject:str];

    if (!isMatch) {

        UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请输入正确的手机号码" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

        [alert show];

        return NO;

    } 

    return YES;

}

//是否为字符串

+ (BOOL) isBlankString:(NSString *)string {

    if (string == nil || string == NULL || [string  isEqual: @"<null>"]) {

        return YES;

    }

    if ([string isKindOfClass:[NSNull class]]) {

        return YES;

    }

    if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {

        return YES;

    }

    return NO;

}

//字符串是否为纯数字

+ (BOOL)isPureNumandCharacters:(NSString *)string

{

    string = [string stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]];

    if(string.length > 0)

    {

        return NO;

    }

    return YES;

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM