how would i go about limiting the iphonekeyboard to only allow numbers to be entered into the gui text?
this is the script im using to get the keyboard up
var inputText : String = "text";
private var keyboard : iPhoneKeyboard;
// Updates button's text while user is typing
function OnGUI() {
if (GUI.Button(Rect(0, 10, 200, 32), inputText))
keyboard = iPhoneKeyboard.Open(inputText);
if (keyboard)
inputText = keyboard.text;
}
The iPhoneKeyboard functionality itself is a bit limited. My suggestion would be to simply check the text value each frame and parse out all non-numeric characters. You could easily do this with something similar to the following code:
myStringBuilder.Length = 0;
for(int i = 0; i < inputText.Length; i++)
{
if (char.IsNumber(inputText[i]))
myStringBuilder.Append(inputText[i]);
}
If you are worried about performance you could use this as a validation when the user finishes, then prompt them if they enter an invalid character. I doubt you will have too much going on while the user is entering this information so I would not worry about performance unless it turns out to be an issue.
You can change which keyboard appears by using the iPhoneKeyboardType enumeration. If you set it to iPhoneKeyboardType.NumberPad you will get a keypad that is designed for number entry.
var inputText : String = "text";
private var keyboard : iPhoneKeyboard;
// Updates button's text while user is typing
function OnGUI() {
if (GUI.Button(Rect(0, 10, 200, 32), inputText))
keyboard = iPhoneKeyboard.Open(inputText, iPhoneKeyboardType.NumberPad);
if (keyboard)
inputText = keyboard.text;
}
i tried that but it seems to just forward me to where the numbers are, but not actually be a “number pad” so the user can still type in a non number character
Is there anyway to get rid of the done button and the input box to leave just the number pad? I’ve seen it this way on other apps. It seems daft if you press on a editbox and then this pad appears and duplicates the input box.
Can you not set inputType with the new TouchScreenKeyboard?? I’m surprised how limiting it is. I just want to bring up the iOS numeric pad…is this not possible?