-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jasper Blues
committed
Sep 8, 2013
1 parent
e236cd8
commit 65bdf76
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2013, Jasper Blues & Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface TyphoonStringUtils : NSObject | ||
|
||
+ (BOOL)isAlpha:(NSString*)candidate; | ||
|
||
+ (BOOL)isAlphaOrSpaces:(NSString*)candidate; | ||
|
||
|
||
+ (BOOL)isAlphanumeric:(NSString*)candidate; | ||
|
||
+ (BOOL)isAlphanumericOrDash:(NSString*)candidate; | ||
|
||
|
||
+ (BOOL)isMemberOfCharacterSet:(NSString*)string characterSet:(NSMutableCharacterSet*)characterSet; | ||
|
||
+ (BOOL)isNotEmpty:(NSString*)candidate; | ||
|
||
+ (BOOL)isEmailAddress:(NSString*)candidate; | ||
|
||
|
||
+ (BOOL)hasMinimumLength:(NSString*)candidate length:(int)length; | ||
|
||
@end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// | ||
// TYPHOON FRAMEWORK | ||
// Copyright 2013, Jasper Blues & Contributors | ||
// All Rights Reserved. | ||
// | ||
// NOTICE: The authors permit you to use, modify, and distribute this file | ||
// in accordance with the terms of the license agreement accompanying it. | ||
// | ||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
|
||
#import "TyphoonStringUtils.h" | ||
|
||
|
||
@implementation TyphoonStringUtils | ||
|
||
|
||
+ (BOOL)isAlpha:(NSString*)candidate | ||
{ | ||
return [self isMemberOfCharacterSet:candidate characterSet:[NSCharacterSet letterCharacterSet]]; | ||
} | ||
|
||
+ (BOOL)isAlphaOrSpaces:(NSString*)candidate | ||
{ | ||
NSMutableCharacterSet* characterSet = [NSMutableCharacterSet letterCharacterSet]; | ||
[characterSet addCharactersInString:@" "]; | ||
return [self isMemberOfCharacterSet:candidate characterSet:characterSet]; | ||
} | ||
|
||
+ (BOOL)isAlphanumeric:(NSString*)candidate | ||
{ | ||
return [self isMemberOfCharacterSet:candidate characterSet:[NSCharacterSet alphanumericCharacterSet]]; | ||
} | ||
|
||
+ (BOOL)isAlphanumericOrDash:(NSString*)candidate | ||
{ | ||
NSMutableCharacterSet* characterSet = [NSMutableCharacterSet alphanumericCharacterSet]; | ||
[characterSet addCharactersInString:@"-_."]; | ||
return [self isMemberOfCharacterSet:candidate characterSet:characterSet]; | ||
} | ||
|
||
|
||
+ (BOOL)isMemberOfCharacterSet:(NSString*)string characterSet:(NSMutableCharacterSet*)characterSet | ||
{ | ||
return ([string rangeOfCharacterFromSet:[characterSet invertedSet]].location != NSNotFound) ? NO : YES; | ||
} | ||
|
||
+ (BOOL)isNotEmpty:(NSString*)candidate | ||
{ | ||
if ([candidate length] == 0) | ||
{ | ||
return NO; | ||
} | ||
|
||
if (![[candidate stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]) | ||
{ | ||
return NO; | ||
} | ||
return YES; | ||
} | ||
|
||
+ (BOOL)isEmailAddress:(NSString*)candidate | ||
{ | ||
NSString* emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; | ||
NSPredicate* emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; | ||
return [emailTest evaluateWithObject:candidate]; | ||
} | ||
|
||
|
||
+ (BOOL)hasMinimumLength:(NSString*)candidate length:(int)length | ||
{ | ||
return ([candidate length] >= length) ? YES : NO; | ||
} | ||
|
||
@end |
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