i want to restrict user from entering space in a UITextField. for this i m using this code
- (BOOL)textField:(UITextField *)textField shouldChangeCharacters
Below is what I am using for password and confirm password
In PrefixHeader.pch
file add below
#define NONACCEPTABLE_PASSWORD_CHARACTERS @" "
And in code use below.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField==passwordTF || textField==confirmPasswordTF) {
NSCharacterSet *cs = [NSCharacterSet characterSetWithCharactersInString:NONACCEPTABLE_PASSWORD_CHARACTERS];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}
return YES;
}