I have a signup view controller where the user needs to enter an email address, a username, and a password.
For the username and password fields, right now you can currently sign up with a username like "user%$&" and a password like "password%^&$". I don't want people to be able to use these special characters.
I want to make it so that the username and password fields can only be submitted with alphanumeric characters aka letters and numbers. I have found some methods to do this, but they are confusing and I need this to work specifically with my code.
Here is some of the code that I perform when a user has entered an email, username, and password and they press the submit button:
NSString *user = [_usernameEntry text];
NSString *pass = [_passwordEntry text];
NSString *email = [_emailEntry text];
self.userSubmittedUsername = user;
if ([user length] < 4 || [pass length] < 4) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Entry" message:@"Username and Password must both be at least 4 characters long." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
} else if ([email length] < 8) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Entry" message:@"Please enter your email address." delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alert show];
} else {
I would just like to add another else if
into the above code and have it show an alert view if there are any characters that are NOT letters or numbers.
Thanks.