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