0

I'm trying to get ONLY number for input in react-native, i know if we want to get number, we can use keyboardType="numeric" ,but problem is, nothing can stop me from input * + #

Like below image, i still can iput these symbol without any problem enter image description here

I search stackoverflow for this, but that answer was outdated, it was 2016 and that time, keyboard only have . symbol.

For 5 years later, i think maybe someone will get struggle like me, so if you solved this, please help, thank you a lots

CODEforDREAM
  • 863
  • 1
  • 8
  • 24
  • Are you asking how to display a keyboard with only digits, or how to prevent any non-digits from being entered in the input? Those are very different things. – windowsill Sep 23 '21 at 03:44
  • It will be nice if the keyboard display only digit, i thought it can't, so i was trying to prevent any non-digit being entered – CODEforDREAM Sep 23 '21 at 03:46
  • The numeric show us both digits and symbol above, so i don't know what to do – CODEforDREAM Sep 23 '21 at 03:47
  • 1
    You are right, the keyboard belongs to your phone so react-native has no control over it. You can use a number picker instead of a text input to allow only numbers. Or use a controlled input to with a regex like this `.replace(/[^0-9]/g, '')`. – windowsill Sep 23 '21 at 03:49
  • Can you give me an example, i understand your idea, but i have no idea how to apply this – CODEforDREAM Sep 23 '21 at 03:56
  • There's tones of examples... https://stackoverflow.com/a/47751269/5708566 – windowsill Sep 23 '21 at 04:06

0 Answers0