mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-01 16:06:59 +00:00
move email-validation to a common place
instead of c&p it - lazy bastard :-)
This commit is contained in:
parent
79df67ec4a
commit
9747495ae3
@ -88,27 +88,11 @@
|
||||
}
|
||||
|
||||
#pragma mark - Private methods
|
||||
|
||||
//TODO: extract from feedbackviewcontroller and move to common place
|
||||
- (BOOL)validateEmail {
|
||||
NSString *emailRegex =
|
||||
@"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
|
||||
@"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
|
||||
@"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
|
||||
@"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
|
||||
@"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
|
||||
@"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
|
||||
@"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
|
||||
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES[c] %@", emailRegex];
|
||||
|
||||
return [emailTest evaluateWithObject:self.email];
|
||||
}
|
||||
|
||||
- (BOOL)allRequiredFieldsEntered {
|
||||
if (self.requirePassword && [self.password length] == 0)
|
||||
return NO;
|
||||
|
||||
if ([self.email length] > 0 && ![self validateEmail])
|
||||
if (![self.email length] || !BITValidateEmail(self.email))
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
|
@ -106,21 +106,6 @@
|
||||
}
|
||||
|
||||
#pragma mark - Private methods
|
||||
|
||||
- (BOOL)validateEmail {
|
||||
NSString *emailRegex =
|
||||
@"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
|
||||
@"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
|
||||
@"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
|
||||
@"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
|
||||
@"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
|
||||
@"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
|
||||
@"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
|
||||
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES[c] %@", emailRegex];
|
||||
|
||||
return [emailTest evaluateWithObject:self.email];
|
||||
}
|
||||
|
||||
- (BOOL)allRequiredFieldsEntered {
|
||||
if ([self.manager requireUserName] == BITFeedbackUserDataElementRequired && [self.name length] == 0)
|
||||
return NO;
|
||||
@ -128,7 +113,7 @@
|
||||
if ([self.manager requireUserEmail] == BITFeedbackUserDataElementRequired && [self.email length] == 0)
|
||||
return NO;
|
||||
|
||||
if ([self.email length] > 0 && ![self validateEmail])
|
||||
if ([self.email length] > 0 && !BITValidateEmail(self.email))
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
|
@ -73,6 +73,7 @@
|
||||
NSBundle *BITHockeyBundle(void);
|
||||
NSString *BITHockeyLocalizedString(NSString *stringToken);
|
||||
NSString *BITHockeyMD5(NSString *str);
|
||||
BOOL BITValidateEmail(NSString *email);
|
||||
|
||||
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
|
||||
|
||||
|
@ -73,3 +73,17 @@ NSString *BITHockeyMD5(NSString *str) {
|
||||
result[14], result[15]
|
||||
];
|
||||
}
|
||||
|
||||
BOOL BITValidateEmail(NSString *email) {
|
||||
NSString *emailRegex =
|
||||
@"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0-9!#$%\\&'*+/=?\\^_`{|}"
|
||||
@"~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\"
|
||||
@"x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-z0-9](?:[a-"
|
||||
@"z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\\[(?:(?:25[0-5"
|
||||
@"]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-"
|
||||
@"9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21"
|
||||
@"-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])";
|
||||
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES[c] %@", emailRegex];
|
||||
|
||||
return [emailTest evaluateWithObject:email];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user