iOS 判断只有数字、小数点和减号

#define NUMBERS @"0123456789.-"

//数字

#define NUM @"0123456789"

//字母

#define ALPHA @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

//数字和字母

#define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

//数字和点

#define NUMANDD @".0123456789"

 

 

#pragma mark -是否只包含数字,小数点,负号

-(BOOL)isOnlyhasNumberAndpointWithString:(NSString *)string{

    NSCharacterSet *cs=[[NSCharacterSet characterSetWithCharactersInString:NUMBERS] invertedSet];

    NSString *filter=[[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];

    return [string isEqualToString:filter];

}

posted @ 2016-04-08 12:44  爱生活爱代码  阅读(1908)  评论(0编辑  收藏  举报