标签:手机号码 提示 cancel 数字 man ios 判断 numa ret
#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;
}
iOS判断字符串是否为手机号,iOS判断字符串是是否为字符串,iOS判断字符串是否为纯数字
标签:手机号码 提示 cancel 数字 man ios 判断 numa ret
原文地址:http://www.cnblogs.com/caodedi-88/p/6323264.html