- Home /
How can I make an input field only take in numbers and decimals?
I want to make an ip input field... how can I disable any other characters?
Are you using the new GUI system (with Canvas, etc.) or the old one (OnGUI method)?
I think you can use the char class to check if the input string contains any characters otehr than what you specified, and remove those from the string.
Answer by Somian · Jun 13, 2015 at 08:25 PM
You could check the string the user entered contains stuff you don't want after every character input via…
myString.Contains("a")
and then, if yes, immediately delete it.
via…
myString = myString.Remove(myString.length - 1);
You'll need a lot of checks for all sorts of characters, though.
a faster way would be to iterate through the string and remove a character if it is not 1,2,3, if the set of characters you allow is smaller than the set of characters you disallow.
Your answer
Follow this Question
Related Questions
gameobject.setActive(true) || (false) hiccups game for 3 to 5 seconds 4 Answers
Locking OVRCamerarig for a few seconds to load script. 2 Answers
keep collider disabled even when the player re-enter the scene 1 Answer
Disable collision before collision actually happens 1 Answer
Spawning different GameObjects once player reaches certain score 0 Answers