Last active
February 7, 2018 13:53
-
-
Save FWEugene/dbcd826ebe27aa429932866391020a6d to your computer and use it in GitHub Desktop.
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> | |
#import "TextInputValidator.h" | |
@interface EmailStringValidator : NSObject <TextInputValidator> | |
@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
#import "EmailStringValidator.h" | |
@implementation EmailStringValidator | |
-(BOOL)isValidString:(NSString *)string { | |
NSString *emailPattern = @"^((([!#$%&'*+\\-/=?^_`{|}~\\w])|([!#$%&'*+\\-/=?^_`{|}~\\w][!#$%&'*+\\-/=?^_`{|}~\\.\\w]{0,}[!#$%&'*+\\-/=?^_`{|}~\\w]))[@]\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*)$"; | |
NSError *error = nil; | |
NSRegularExpression *regexp = [NSRegularExpression regularExpressionWithPattern:emailPattern options:0 error:&error]; | |
NSAssert(error != nil, @"Validator Error"); | |
NSUInteger numberOfMatches = [regexp numberOfMatchesInString:string | |
options:0 | |
range:NSMakeRange(0, [string length])]; | |
return numberOfMatches >0; | |
} | |
@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
#import <Foundation/Foundation.h> | |
@protocol TextInputValidator <NSObject> | |
-(BOOL) isValidString:(NSString *) string; | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment