Created
December 17, 2014 22:10
-
-
Save johanforssell/7f0776e30eb00584db0b to your computer and use it in GitHub Desktop.
NSString category for filtering text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSString (Filter) | |
/// Only allow A-Z, a-z, 0-9 and underscore. | |
- (BOOL)isAlphanumericOrUnderscore; | |
@end | |
@implementation NSString (Filter) | |
- (BOOL)isAlphanumericOrUnderscore | |
{ | |
NSMutableCharacterSet *set = [NSMutableCharacterSet alphanumericCharacterSet]; | |
[set addCharactersInString:@"_"]; | |
return ([self rangeOfCharacterFromSet:[set invertedSet]].location == NSNotFound); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment