Message Boards Message Boards

Back

RE: How to constrain input to numbers only on an text input box?

Toggle
How to constrain input to numbers only on an text input box?
text input regular expression number input
Answer
10/26/20 5:59 PM
Is there any way to restrict user input to numbers only on a text input object?

Please show me how to do that.
0 (0 Votes)

RE: How to constrain input to numbers only on an text input box?
Answer
10/26/20 8:18 PM as a reply to D Singh.
Hi Daljit,
Normally you would use a Number Input object to collect numerical entries from learners. However, if you don't like the default "0", or you have another reason not to use the Number Input object, you can instead use a Text Input object, and an action that removes any non-numeric characters. But you won't get the nice formatting options (e.g., $1,000). If you want to do that, here's how - https://www.screencast.com/t/wYaWtYhd

Regex is extremely powerful for text manipulation, and you can look up all sorts of shortcuts for that. "\W" is one that I use for taking "The quick brown fox is #rabid!!!" and making it web safe, "The_quick_brown_fox_is__rabid___".

Hope that helps!

Attachments:

Attachment

0 (0 Votes)