限制 TextField 充当数字步进器
我正在从头开始制作数字步进器,因此我希望我的文本字段仅接受以下格式的数字:xx.x、xx、x 或 xx,其中 x 是数字。例如: 可接受的数字: 1 22 15.5 3.5
无 可接受的数字: 213 33.15 4332 1.65
也许这会有所帮助: http://livedocs.adobe.com/flash/9.0 /ActionScriptLangRefV3/flash/text/TextField.html#restrict
这是我到目前为止得到的:
var tx:TextField = new TextField();
tx.restrict="0-9."; //Maybe there is a regular expression string for this?
tx.type=TextFieldType.INPUT;
tx.border=true;
您可以在 Flash 中复制此内容,它应该可以工作。
非常感谢各位好心先生的帮助。
I am making a numeric stepper from scratch, so I want my text field to only accept numbers in this format: xx.x, x.x, x, or xx where x is a number. For example:
Acceptable numbers:
1
22
15.5
3.5
None Acceptable numbers:
213
33.15
4332
1.65
Maybe this will help some how:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.html#restrict
This is what I got so far:
var tx:TextField = new TextField();
tx.restrict="0-9."; //Maybe there is a regular expression string for this?
tx.type=TextFieldType.INPUT;
tx.border=true;
You can copy past this in flash and it should work.
Thank you very much for your help good sirs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与 TheDarklins 的答案非常相似,但更优雅一些。实际上,
_tf.restrict
已过时,但我仍然建议使用它。这里的两个事件监听器执行完全相同相同的功能。对于那些喜欢较小代码的人来说,它是一行编写的。另一个适合那些喜欢逐行查看正在发生的事情的人。
对于事件侦听器的更详细版本,
我必须允许 xx. 作为有效响应,否则您需要输入 123,然后返回一个空格并输入 。对于 12.3。这实在是不好。因此
12.
现在在技术上是有效的。Very similar to TheDarklins answer, but a little more elegant. And actually renders
_tf.restrict
obsolete, but I would still recommend using it.Both of these event listeners here do the EXACT same function identically. One is written in a one line for those who like smaller code. The other is for those who like to see what's going on line by line.
for a more broken down version of the event listener
I have had to allow
xx.
as a valid response otherwise you would need to type 123 then go back a space and type . for 12.3. That is JUST NOT NICE. So12.
is now technically valid.