i want to restrict user from entering space in a UITextField. for this i m using this code
- (BOOL)textField:(UITextField *)textField shouldChangeCharacters
This will search to see if your replacement string contains a space, if it does then it throws the error message up, if it doesn't it returns YES.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSRange spaceRange = [string rangeOfString:@" "];
if (spaceRange.location != NSNotFound)
{
UIAlertView *error = [[UIAlertView alloc] initWithTitle:@"Error" message:@"You have entered wrong input" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[error show];
return NO;
} else {
return YES;
}
}