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];
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) {
- (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];
}
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