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

6
  • 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. Commented Sep 23, 2021 at 3: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 Commented Sep 23, 2021 at 3:46
  • The numeric show us both digits and symbol above, so i don't know what to do Commented Sep 23, 2021 at 3: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, ''). Commented Sep 23, 2021 at 3:49
  • Can you give me an example, i understand your idea, but i have no idea how to apply this Commented Sep 23, 2021 at 3:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.