Skip to content

TextInput briefly displays restricted characters before validation removes them when using onChangeText #47252

Open

Description

@rvmaher

Description

Hi there,
Just wanted to bring up an issue that many of us have come across. When using TextInput with validation in onChangeText, restricted text still flashes for a moment before it gets removed. This is a pretty common need in apps, where real-time validation is used to guide user input (like blocking specific characters or setting a format). But right now, seeing those restricted characters pop up briefly makes the input feel a bit off.
There are many Workarounds and hacks for this but don’t quite fix the experience entirely. Is there any chance this could be smoothed out natively in the future?

Steps to reproduce

Screenshot 2024-10-28 at 18 10 02

React Native Version

0.76.0

Affected Platforms

Runtime - Android, Runtime - iOS

Output of npx react-native info

Not needed

Stacktrace or Logs

Not needed

Reproducer

https://snack.expo.dev/fVO2DXQPPqQVlm9QBZ2ms

Screenshots and Videos

No response

Activity

  1. react-native-bot commented on Oct 28, 2024

    @react-native-bot
    Collaborator
    ⚠️ Missing Reproducible Example
    ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
    • If your bug is UI related: a Snack
    • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.
  2. react-native-bot commented on Oct 28, 2024

    @react-native-bot
    Collaborator
    ⚠️ Missing Reproducible Example
    ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  3. rvmaher commented on Oct 28, 2024

    @rvmaher
    Author
  4. added
    Issue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.
    and removed
    Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.
    on Oct 29, 2024
  5. cortinico commented on Oct 29, 2024

    @cortinico
    Contributor

    Repro Snack : snack.expo.dev/fVO2DXQPPqQVlm9QBZ2ms

    Can you share a video? As on the Snack it doesn't behave as you described

  6. rvmaher commented on Nov 7, 2024

    @rvmaher
    Author
    TextinputFlash.webm
  7. s77rt commented on Nov 13, 2024

    @s77rt
    Contributor

    This is a known limitation due to the onChangeText event being async. If you need to just prevent some chars from being inserted you can use this regex approach https://github.com/s77rt/react-native/tree/TextInput-regex (proposal).

    // No @ allowed
    <TextInput regex="^[^@]*$" />

    Please note that the regex prop can't be used to validate intermediate state.

  8. olivertylsar commented on Mar 28, 2025

    @olivertylsar

    Does Fabric change anything in relation to this problem? There was hope that it might be possible after it gets introduced.

    #28535 (comment)

    @elicwhite Any news on this one?

  9. rohit9625 commented on Apr 10, 2025

    @rohit9625

    I am also facing this issue. Can we prevent pasting characters using onChange prop?

  10. rohit9625 commented on Apr 10, 2025

    @rohit9625

    The regex prop is not available in TextInput. Is it not implemented yet? Is it gonna take time? Can I help with this implementation?

  11. rohit9625 commented on Apr 10, 2025

    @rohit9625

    Hey @s77rt, could you please help me with this issue? When copying an image from the Gallery and pasting it on the React Native's Text Input, the binary content of the image gets pasted in the textInput. However, I've tried restricting the input but it still appears for a fraction of a second.
    I am using a Samsung A14 device with API level 34. It seems like we cannot prevent the flashing when restricting input value but does pasting image content is expected?

    This is before input restriction:

    Recent_Repro_Paste_Image.mp4

    This is after input restriction:

    Recent_Repro_After_Paste_Image_Fix.mp4
  12. s77rt commented on Apr 11, 2025

    @s77rt
    Contributor

    @rohit9625 The mentioned issue should not be fixed with regex. In that case the paste functionality is what should prevent this text pasting.

  13. rohit9625 commented on Apr 11, 2025

    @rohit9625

    But how? This behavior is device specific. Maybe, some devices stores the binary directly into the clipboard.

  14. veliseev93 commented on Apr 29, 2026

    @veliseev93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: TextInputRelated to the TextInput component.Issue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.Needs: AttentionIssues where the author has responded to feedback.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions