How can i detect which key was pressed on textfield's keyboard?

I need to make it not allow write many 0's if before 0 is nothing. Is there any method of textfield?

Upvotes: 0

Views: 76

Answers (1)

Rajesh73
Rajesh73

Reputation: 342

Modify this sample code as per your requirement.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    if ([string isEqualToString:@" "]) // Preventing Spaces here {
        return NO;
    }
    else{
        return YES;
    }
}

Upvotes: 1

Related Questions