| Reference | Downloads | Github

How to limit input of Textbox to numeric values only

Hello everyone.

I would like you to teach me how I can limit input of Textbox only to numeric values, specifically 0 - 1000.
Textbox components accept all types of text by default.
However, I would like to make a routine as below to collect valid data.

1: Participant can input numeric values and end a routine by pressing key (e.g., space).
2: If participant tries to input other values, such as alphabet and NULL, error message appears and they are asked to input values again.
3: Values are collected (only valid ones are enough).

All I have done so far is make 1 procedure with builder.

I feel I need to code, but this beginner of Python fails to do so.

I appreciate if you give me a hand :slight_smile:
Thank you!

Hi There,

I actually made a little demo that might help here! textBox.psyexp (25.5 KB)

Hopefully the code components in this help you on your way :slight_smile:


Thank you so much!
I appreciate your kind help :smiling_face_with_three_hearts:

Could I ask another question?
Do you think it is error-occuring code that a routine (trial) of input text is ended by key pressing?
I set key response (space) to end the routine instead of click the button in your demo, and it seems to work.
I know there is Alert 4405, “Editable textbox component textbox and keyboard component key_resp in the same routine may compete for keypresses”

I would be very grateful if you could respond to the question above.

Thank you.

Hi There, That looks like an alert rather than an error (so shouldn’t stop the experiment running) it is just warning you that you have a keyboard response and an editable textbox in the same routine (which is fine if you want participants to submit their typed response by pressing a certain key