留言板 留言板

返回

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

触发器
How to constrain input to numbers only on an text input box?
text input regular expression number input
答复
20-10-26 下午5:59
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 票)

RE: How to constrain input to numbers only on an text input box?
答复
20-10-26 下午8:18 回复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!
0 (0 票)