Created
April 6, 2013 20:04
-
-
Save jpotts18/5327429 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
// | |
// GPInputValidator.h | |
// GrowingPains | |
// | |
// Created by Kyle Clegg on 11/20/12. | |
// Copyright (c) 2012 Kyle Clegg. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface InputValidator : NSObject | |
+ (BOOL) isValidName:(NSString *)name; | |
+ (BOOL) isValidEmail:(NSString* )emailAddress; | |
+ (BOOL) isValidPassword:(NSString *)password; | |
+ (BOOL) isValidPasswordLength:(NSString *)password; | |
+ (BOOL) isValidUsername:(NSString *)username; | |
+ (BOOL) isValidUsernameLength:(NSString *)username; | |
@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
// | |
// GPInputValidator.m | |
// GrowingPains | |
// | |
// Created by Kyle Clegg on 11/20/12. | |
// Copyright (c) 2012 Kyle Clegg. All rights reserved. | |
// | |
#import "InputValidator.h" | |
@implementation InputValidator | |
+ (BOOL) isValidName:(NSString *)name { | |
return name.length > 0 ? YES : NO; | |
} | |
+ (BOOL) isValidEmail:(NSString *)emailAddress { | |
// Email validation regex | |
NSString *emailRegex = | |
@"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; | |
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; | |
return [emailTest evaluateWithObject:emailAddress]; | |
} | |
+ (BOOL) isValidPassword:(NSString *)password { | |
NSPredicate *passwordTest = [NSPredicate predicateWithFormat:@"SELF MATCHES '.*( ).*'"]; | |
BOOL hasSpace = [passwordTest evaluateWithObject:password]; | |
return !hasSpace; | |
} | |
+ (BOOL) isValidPasswordLength:(NSString *)password { | |
if ([password length] >= 6) { | |
return YES; | |
} | |
return NO; | |
} | |
+ (BOOL) isValidUsername:(NSString *)username { | |
NSString *usernameRegex = | |
@"^[A-Za-z0-9\\-\\_]*"; | |
NSPredicate *usernameTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", usernameRegex]; | |
return [usernameTest evaluateWithObject:username]; | |
} | |
+ (BOOL) isValidUsernameLength:(NSString *)username { | |
if ([username length] >= 3) { | |
return YES; | |
} | |
return NO; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment