I would like to validate UITextField and display an UIAlertView if there is an error.
Previously I used the code below. It works perfectly with 2 UITexfields but with many UITextfield it's not possible.
Any tips how to display an UIAlertView to validate my UITexfields ?
- (void)processFieldEntries {
NSString *usernameString = usernameField.text;
NSString *passwordString = passwordField.text;
NSString *firstNameString = firstNameField.text;
NSString *nameString = nameField.text;
NSString *cityString = cityField.text;
NSString *errorText = @"Enter";
NSString *usernameBlankText = @" a username";
NSString *passwordBlankText = @" a password";
NSString *prenomBlankText = @" a firstname";
NSString *nomBlankText = @" a name";
NSString *joinText = @", ";
BOOL textError = NO;
if (identifiantString.length == 0 || motDePasseString.length == 0 || prenomString.length == 0 || nomString.length == 0 || idPoubelle.length == 0) {
textError = YES;
if (usernameString.length == 0) {
errorText = [errorText stringByAppendingString:usernameBlankText];
}
if (usernameString.length == 0 || passwordString.length == 0) {
if (usernameString.length == 0) {
errorText = [errorText stringByAppendingString:joinText];
}
errorText = [errorText stringByAppendingString:passwordBlankText];
}
}
if (textError) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:errorText message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
[alertView show];
return;
}
}