mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
If an email field is entered, validate the string and only allow addresses that look correct
This commit is contained in:
@@ -106,6 +106,20 @@
|
||||
|
||||
#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 %@", emailRegex];
|
||||
|
||||
return [emailTest evaluateWithObject:self.email];
|
||||
}
|
||||
|
||||
- (BOOL)allRequiredFieldsEntered {
|
||||
if ([self.manager requireUserName] == BITFeedbackUserDataElementRequired && [self.name length] == 0)
|
||||
return NO;
|
||||
@@ -113,6 +127,9 @@
|
||||
if ([self.manager requireUserEmail] == BITFeedbackUserDataElementRequired && [self.email length] == 0)
|
||||
return NO;
|
||||
|
||||
if ([self.email length] > 0 && ![self validateEmail])
|
||||
return NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user