<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Formatter/isPartialStringValid(_:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFormatter(im)isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:"
  },
  "title" : "isPartialStringValid(_:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:)"
}
-->

# isPartialStringValid(_:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:)

This method should be implemented in subclasses that want to validate user changes to a string in a field, where the user changes are not necessarily at the end of the string, and preserve the selection (or set a different one, such as selecting the erroneous part of the string the user has typed).

```
func isPartialStringValid(_ partialStringPtr: AutoreleasingUnsafeMutablePointer<NSString>, proposedSelectedRange proposedSelRangePtr: NSRangePointer?, originalString origString: String, originalSelectedRange origSelRange: NSRange, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool
```

## Parameters

`partialStringPtr`

The new string to validate.

`proposedSelRangePtr`

The selection range that will be used if the string is accepted or replaced.

`origString`

The original string, before the proposed change.

`origSelRange`

The selection range over which the change is to take place.

    If the user change is a deletion,     `origSelRange`     contains the range of the deleted characters.

`error`

If non-`nil`, if validation fails contains an `NSString` object that describes the problem.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if `partialStringPtr` is acceptable, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

In a subclass implementation, evaluate `partialString` according to the context. Return <doc://com.apple.documentation/documentation/Swift/true> if `partialStringPtr` is acceptable and <doc://com.apple.documentation/documentation/Swift/false> if `partialStringPtr` is unacceptable. If you return <doc://com.apple.documentation/documentation/Swift/false> and assign a new string to `partialStringPtr` and a new range to `proposedSelRangePtr`, the string and selection range are changed, otherwise, if no values are assigned to `partialStringPtr` or `proposedSelRangePtr`, the change is rejected. If you return <doc://com.apple.documentation/documentation/Swift/false>, you can also return by indirection an `NSString` object (in `error`) that explains the reason why the validation failed; the delegate (if any) of the `NSControl` object managing the cell can then respond to the failure in control:didFailToValidatePartialString:errorDescription:.

---

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)