Skip to content

Instantly share code, notes, and snippets.

@johanforssell
Created December 17, 2014 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanforssell/7f0776e30eb00584db0b to your computer and use it in GitHub Desktop.
Save johanforssell/7f0776e30eb00584db0b to your computer and use it in GitHub Desktop.
NSString category for filtering text
#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