Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex Flex3 Air中的文本输入限制_Apache Flex_Actionscript 3_Air - Fatal编程技术网

Apache flex Flex3 Air中的文本输入限制

Apache flex Flex3 Air中的文本输入限制,apache-flex,actionscript-3,air,Apache Flex,Actionscript 3,Air,我需要限制用户,只允许第一个字符为+或-或0-9,另一个字符为0-9..我怎么做 在正则表达式验证器中,下面的表达式可以工作,但我需要在restrict字段中 <mx:TextInput id="txtTop" restrict="[0-9+-][0-9]*$" /> 有效值为 +023 -123 二十三 0 无效的 +-123 fsaf -+2132 提前感谢根据字符串长度更改restrict的值 <mx:TextInput id="ti" restrict="[0-

我需要限制用户,只允许第一个字符为+或-或0-9,另一个字符为0-9..我怎么做

在正则表达式验证器中,下面的表达式可以工作,但我需要在restrict字段中

<mx:TextInput id="txtTop"  restrict="[0-9+-][0-9]*$" />

有效值为

+023

-123

二十三

0

无效的

+-123

fsaf

-+2132


提前感谢

根据字符串长度更改
restrict
的值

<mx:TextInput id="ti" restrict="[0-9+\-]" change="onChange(event)"/>

private function onChange(event:Event):void
{
    if(ti.text.length > 0)
        ti.restrict = "[0-9]";
    else
        ti.restrict = "[0-9+\-]"
}

私有函数onChange(事件:event):void
{
如果(ti.text.length>0)
ti.restrict=“[0-9]”;
其他的
ti.restrict=“[0-9+\-]”
}

限制字段中不需要括号([和])作为TextInput.restrit是字符串类型。和限制只能强制启用或禁用单个字符。为了满足您的要求,您需要对照正则表达式检查文本字符串,如果文本字符串无效,则删除最后输入的字符。所以使用restrict来限制用户只输入那些字符(0-9+-),并在TextInput发生变化时使用regex match来验证。省略方括号听起来很合理,但奇怪的是,我的文本输入不接受没有方括号的
-
(带或不带转义)。嗨,伙计,它允许在第一个字符和一些符号中使用字母。。在单个Regexpression?中不可能执行此操作,这是对更改事件执行操作的唯一方法吗!!。。。谢谢你的回复。不,它不允许字母或符号-我再次测试。您使用的是什么版本的flex?不能使用单个正则表达式执行此操作-restrict属性采用字符串而不是正则表达式。