Instance Method


Asks the delegate if the specified text should be changed.


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;



The text field containing the text.


The range of characters to be replaced.


The replacement string for the specified range. During typing, this parameter normally contains only the single new character that was typed, but it may contain more characters if the user is pasting text. When the user deletes one or more characters, the replacement string is empty.

Return Value

YES if the specified text range should be replaced; otherwise, NO to keep the old text.


The text field calls this method whenever user actions cause its text to change. Use this method to validate text as it is typed by the user. For example, you could use this method to prevent the user from entering anything but numerical values.

See Also

Editing the Text Field’s Text

- textFieldShouldClear:

Asks the delegate if the text field’s current contents should be removed.

- textFieldShouldReturn:

Asks the delegate if the text field should process the pressing of the return button.