X-Git-Url: https://code.grnet.gr/git/pithos-ios/blobdiff_plain/ba01f5a7e8c2db54308a046d5a8eb4dd1541ed0e..d6b38316924ac9fff419909a650e0572f99b3eaa:/Classes/EditPermissionsViewController.m diff --git a/Classes/EditPermissionsViewController.m b/Classes/EditPermissionsViewController.m index 6c0dd94..9fc8e2c 100644 --- a/Classes/EditPermissionsViewController.m +++ b/Classes/EditPermissionsViewController.m @@ -135,7 +135,7 @@ UITextField *textField = [[UITextField alloc] initWithFrame:rect]; [textField setFrame:rect]; [textField setClearButtonMode:UITextFieldViewModeWhileEditing]; - [textField setBackgroundColor:[UIColor whiteColor]]; + [textField setBackgroundColor:[UIColor clearColor]]; [textField setOpaque:YES]; [textField setAutocorrectionType:UITextAutocorrectionTypeNo]; [textField setAutocapitalizationType:UITextAutocapitalizationTypeNone]; @@ -196,12 +196,8 @@ UITextField *textField = [[cell.contentView subviews] objectAtIndex:0]; newUserName = textField.text; - if ([newUserName length] == 0 - || [[newUserName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0) { - [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; - [self alert:@"Invalid input" message:@"User name field cannot be empty"]; - return; - } + if (![self userInputIsValid:newUserName]) + return; } if (indexPath.section == kPermissions) { @@ -326,10 +322,7 @@ - (void)textFieldDidEndEditing:(UITextField *)textField { - if ([textField.text length] == 0 - || [[textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0) { - [self alert:@"Invalid input" message:@"User name field cannot be empty"]; - } + [self userInputIsValid:textField.text]; } @@ -367,5 +360,25 @@ else return [NSString stringWithFormat:@"%@;%@", readPermissionsString, writePermissionsString]; } +- (BOOL)userInputIsValid:(NSString *)input { + if ([input length] == 0 + || [[input stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0 + ) { + [self alert:@"Invalid input" message:@"User name field cannot be empty"]; + return NO; + } + else { + NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"=,;"]; + if ([input rangeOfCharacterFromSet:set].location != NSNotFound) { + [self alert:@"Invalid input" message:@"User name cannot contain '=', ',' or ';'"]; + return NO; + } + else { + return YES; + } + } + + return YES; +} @end