Number only for Textbox

Get help using Construct 2

Post » Mon Apr 22, 2013 5:32 am

How can i allow number only for my textbox? I don't want the user to type letters or special characters into it.
B
7
S
1
Posts: 4
Reputation: 910

Post » Mon Apr 22, 2013 12:27 pm

So there's no way to do this?
B
7
S
1
Posts: 4
Reputation: 910

Post » Mon Apr 22, 2013 1:38 pm

Hi BrownBear,

It's sitting quietly in Properties -> Type -> Choose "Number"

Cheers,
Greg
B
17
S
3
G
3
Posts: 79
Reputation: 3,698

Post » Mon Apr 22, 2013 4:44 pm

@CJK Thanks but that's not work, i can still type letters into the textbox.
B
7
S
1
Posts: 4
Reputation: 910

Post » Mon Apr 22, 2013 5:21 pm

Here's a way to do it: inputNumbersOnly.capx (r126)
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Mon Apr 22, 2013 5:22 pm

Every time the text changes, run a loop to check to see if each text character is a number. If not, remove the non-number:

Capx

Edit: I didn't see Ramones's post when I replied. His method is very similar, but only stops the user from adding a non-number to the right-most character in the textbox. My capx will check every character (so the player can't add text in the middle of a bunch of numbers already entered). zatyka2013-04-22 17:29:58
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Mon Apr 22, 2013 5:28 pm

@ramones @zatyka Wow, thanks very much. :D
B
7
S
1
Posts: 4
Reputation: 910

Post » Mon Apr 22, 2013 5:36 pm

@zatyka Good point - I didn't think of that.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020


Return to How do I....?

Who is online

Users browsing this forum: zenox98 and 27 guests