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>
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>