How come the number type in a textbox isn't working?

From the Asset Store
Forget about default textbox restrictions, you can create sprites atop of the textbox
  • I set the type of my textbox to number but I still can type letters. How to fix this??

  • The number type doesn't prevent you typing letters (as you know). It just tells the browser what type of input is expected and it's up to the browser how it handles that. For example, some mobile browsers would show a numeric input instead of the text keyboard.

    If you want to enforce number input you need to check what's entered and remove anything that's not a number. Here's one way using regex (although this won't even allow a minus sign or decimal point):

    [attachment=0:2rjimvb0][/attachment:2rjimvb0]

  • ramones Your solution worked but whenever I click any other button thats not numeric, it erases everything already entered in the box. Is there anyway to fix this?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hmm... I only tried in Firefox. In Chrome, it seems that TextBox.Text returns nothing when the input isn't a number. You could store the last value in an instance variable and if the text changes to "" then restore the old value. But then how do you tell the difference between the user typing a letter vs deleting all the text? It might be easier to leave the input type as 'Text'.

  • ramones Yeah I guess. Also, is there anyway to get a permanent dollar sign to stay there? I making a bank for my game and I want an automatic dollar sign to show up when you enter your money in the textbox.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)