Flex restrict 输入限制

Flex中TextInput和TextArea有一个比较有用的属性restrict(约束,限定),看下面例子:
1,<mx:extInput id="test_ti" width="160" maxChars="20" restrict="0-9" text="0"/>
这样,这个输入框最多只能输入20个字符,只能输入0到9之间的数字了,你如果输入别的是输入不进去的
2,<mx:extInput id="test_ti" width="160" maxChars="20" restrict="0-9\." text="0"/>
这样,输入框可以输入0到9之间的数字,以及输入'.',中间必须用'\'分隔开来
3,<mx:extInput id="test_ti" width="160" restrict="0-9\ab" text="0"/>这样,输入框可以输入0到9之间的数字,以及a,或b
4,<mx:extInput id="test_ti" width="160" restrict="a-z" text="0"/>
可以输入a到z之间任何一个英文字母,'-'表示区间,如果要输入'-',就必须加'\',如\-
结论:
用restrict有个好处,就是省去了验证的麻烦,比如检验是否为数字,如果加了restrict="0-9",就不需要检验了,因为这个输入框只能输入0到9之间的数字,别的输不进去

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:x="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" backgroundColor="#A7E460">
<s:layout>
  <s:BasicLayout/>
</s:layout>
<fx:eclarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:eclarations>
<s:extInput x="167" y="190" restrict="0-9"/>
<s:abel x="70" y="190" text="只能输入数字" width="89" height="22" />
<s:abel x="70" y="234" text="只能输入字母" width="89" height="23"/>
<s:TextInput x="167" y="234" restrict="A-Z"/>
</s:Application>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值