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;
}