Created
July 25, 2015 15:01
-
-
Save RadwaEbrahim/e9e01b6e9228277888f2 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
// | |
// NameValidation.h | |
// Radwa | |
// | |
// Created by Radwa Muahammd on 7/1/13. | |
// Copyright (c) 2013 Radwa Muahammd. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface UserDataValidation : NSObject | |
+(BOOL)isNameValid:(NSString*)name; | |
+(BOOL)isEmailVaild:(NSString*)email; | |
+(BOOL)isPasswordVaild:(NSString *)password; | |
+(BOOL)isPassword:(NSString *)password1 matchesRetypedPassword:(NSString *)password2; | |
+(BOOL)isPhoneNumberValid:(NSString*)phoneNumber; | |
+(BOOL)isLargeTextValid:(NSString*)text withMaximumLength:(int)length; //large text like bio,address,list | |
@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
// | |
// NameValidation.m | |
// Radwa | |
// | |
// Created by Radwa Muahammd on 7/1/13. | |
// Copyright (c) 2013 Radwa Muahammd. All rights reserved. | |
// | |
#import "UserDataValidation.h" | |
@implementation UserDataValidation | |
+(BOOL)isNameValid:(NSString*)name{ | |
BOOL isValid = YES; | |
NSString* nameValidation=[name stringByReplacingOccurrencesOfString:@" " withString:@""]; | |
if (nameValidation.length<2 || nameValidation.length>71) { //check length limitation | |
isValid=NO; | |
} | |
else{ // check characters validation | |
NSCharacterSet *alphanumericSet = [NSCharacterSet letterCharacterSet]; | |
NSCharacterSet* nonAlphanumericSet=[alphanumericSet invertedSet];// now it contains all the not allowed character set | |
if ([nameValidation rangeOfCharacterFromSet:nonAlphanumericSet].location != NSNotFound) { | |
#ifdef DEBUG | |
NSLog(@"the name contains illegal characters"); | |
#endif | |
isValid=NO; | |
} | |
} | |
return isValid; | |
} | |
+(BOOL)isEmailVaild:(NSString *)email{ | |
BOOL isValid=NO; | |
if (email.length) { | |
NSString *regExPattern = @"[A-Za-z0-9._%+-]+@(?:[A-Za-z0-9-]+\.)+[A-Za-z]{2,4}"; | |
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regExPattern]; | |
isValid= [emailTest evaluateWithObject:email]; | |
} | |
return isValid; | |
} | |
+(BOOL)isPhoneNumberValid:(NSString *)phoneNumber{ | |
BOOL isValid=YES; | |
NSString* nameValidation=[phoneNumber stringByReplacingOccurrencesOfString:@" " withString:@""]; | |
if (nameValidation.length<10 || nameValidation.length>11) { //check length limitation | |
isValid=NO; | |
} | |
else{ | |
NSCharacterSet *numericSet = [NSCharacterSet decimalDigitCharacterSet]; | |
numericSet=[numericSet invertedSet];// now it contains all the not allowed character set | |
if ([phoneNumber rangeOfCharacterFromSet:numericSet].location != NSNotFound) { | |
#ifdef DEBUG | |
NSLog(@"the phoneNumber contains illegal characters"); | |
#endif | |
isValid=NO; | |
} | |
} | |
return isValid; | |
} | |
+(BOOL)isPasswordVaild:(NSString *)password{ | |
BOOL isValid = YES; | |
NSString* nameValidation=[password stringByReplacingOccurrencesOfString:@" " withString:@""]; | |
if (nameValidation.length< 6 ||nameValidation.length>32) { //if password is empty,or not match the length rule | |
isValid=NO; | |
} | |
return isValid; | |
} | |
+(BOOL)isPassword:(NSString *)password1 matchesRetypedPassword:(NSString *)password2{ | |
BOOL isValid = YES; | |
if (!password2.length || ![password1 isEqualToString:password2]){ | |
//if the retyped password isn't empty and doesn't match the password | |
isValid=NO; | |
} | |
return isValid; | |
} | |
+(BOOL)isLargeTextValid:(NSString *)text withMaximumLength:(int)length{ | |
BOOL isValid = YES; | |
NSString* nameValidation=[text stringByReplacingOccurrencesOfString:@" " withString:@""]; | |
if (!nameValidation.length ||nameValidation.length>length) { | |
isValid=NO; | |
} | |
return isValid; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment