adobe flex用户输入必须包含“/”字符

时间:2014-09-01 06:10:08

标签: flex input special-characters

在我的项目中,我有一个用户输入,前4个字符应该是数字,第五个字符必须是/,有没有办法控制它?

我正在使用Adobe Flash Builder 4.6。我只知道使用限制来输入数字。

EDIT1 : 在遵循Timofei的解决方案后,我修改了我的源代码如下,但它没有生效,只通知用户“此字段是必需的”。无论我在文本框中输入什么,没有警告,我的代码是否有问题?

<?xml version="1.0" encoding="utf-8"?>
<viewer:BaseWidget xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx"
               xmlns:viewer="com.esri.viewer.*"
               right="450" bottom="175" width="320" height="450" widgetConfigLoaded="init()">
<fx:Script>
    <![CDATA[                       
        import mx.controls.Alert;       
        import spark.events.IndexChangeEvent;
        import flash.events.MouseEvent;
        import flash.events.Event;
        import mx.managers.PopUpManager;            

        public function handleEvent():void
        {
            mx.controls.Alert.show("bq no input: " + attr_bqNo.text)    
        }                                   
    ]]>
</fx:Script>
<fx:Declarations>
    <mx:RegExpValidator id="validator" expression="^\d\{4\}/" noMatchError="Error text here" source="{attr_bqNo}" property="text" 
                        trigger="{attr_bqNo}" triggerEvent="change"/>
</fx:Declarations>
    <s:TextInput id="attr_bqNo" x="41" y="29" width="212"/>


<viewer:WidgetTemplate id="attributesearch"
                       width="320" height="450">
    <viewer:layout>
        <s:BasicLayout/>
    </viewer:layout>
    <s:Label x="41" y="15" width="132" height="15" text="BQ No."/>      
    <s:Label x="40" y="59" width="150" height="16" text="Contract No."/>
    <s:TextInput id="attr_contractNo" x="41" y="73" width="213"/>
    <s:Label x="40" y="146" text="Drain Name"/>
    <s:TextInput id="attr_drainName" x="40" y="159" width="213"/>
    <s:Label x="40" y="189" text="Project/Contract Title"/>
    <s:TextInput id="attr_projectTitle" x="40" y="203" width="213"/>        
    <s:Label x="40" y="323" text="Location (Road Name)"/>
    <s:TextInput id="attr_roadName" x="40" y="337" width="213"/>
    <s:Button id="attr_ok" x="68" y="367" label="Ok" click = "handleEvent()"/>
    <s:Button id="attr_clear" x="156" y="367" label="Clear"/>

  </viewer:WidgetTemplate>  
</viewer:BaseWidget>

1 个答案:

答案 0 :(得分:6)

您可以使用RegExpValidator

<fx:Declarations>
        <mx:RegExpValidator id="validator" expression="^\d\{4\}/" noMatchError="Error text here" source="{input}" property="text"
                trigger="{input}" triggerEvent="change"/>
</fx:Declarations>
<s:TextInput id="input"/>

Example

了解validators