<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextFieldDelegate/textField(_:shouldChangeCharactersInRanges:replacementString:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextFieldDelegate(im)textField:shouldChangeCharactersInRanges:replacementString:"
  },
  "title" : "textField(_:shouldChangeCharactersInRanges:replacementString:)"
}
-->

# textField(_:shouldChangeCharactersInRanges:replacementString:)

```
optional func textField(_ textField: UITextField, shouldChangeCharactersInRanges ranges: [NSValue], replacementString string: String) -> Bool
```

## Parameters

`textField`

The text field asking the delegate

`ranges`

The ranges of the text that should be deleted before replacing

## Return Value

Returns YES if the text at the `ranges` should be replaced.

## Discussion\abstract Asks the delegate if the text at the specified `ranges` should be replaced with `string`.
\discussion If this method returns YES then the text field will, at its own discretion, choose any one of the specified `ranges` of text and replace it with the specified `replacementString` before deleting the text at the other ranges.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)