---
title: "Flex-TextInput控件restrict属性"
author: "Hello_Kitty_O"
date: "2010-05-05T23:34:23Z"
tags: ["Flex", "XML"]
categories: ["Web前端"]
slug: "flex-textinput-restrict"
draft: false
lastmod: "2010-05-05T23:39:56Z"
id: 659967
url: "https://hello-kitty-o.iteye.com/blog/659967"
---

Flex中如何通过设置restrict属性，在TextInput控件中限制用户可以输入的字符串
Flex中如何通过设置restrict属性，在TextInput控件中限制用户可以输入的字符串。本例中在restrict属性中设置了“a-z\0-9\-”,也就是只允许用户输入0到9的数字a到z的字母以及间隔符（-）。 

  

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
        layout="vertical" 
        verticalAlign="middle" 
        backgroundColor="white"> 
  
    <mx:Script> 
        <![CDATA[ 
            private function textInput_change(evt:Event):void { 
                arrColl.addItem(evt); 
            } 
        ]]> 
    </mx:Script> 
  
    <mx:ArrayCollection id="arrColl" /> 
  
    <mx:ApplicationControlBar dock="true"> 
        <mx:TextInput id="textInput" 
                restrict="a-z\0-9\-" 
                change="textInput_change(event);" /> 
    </mx:ApplicationControlBar> 
  
    <mx:DataGrid id="dataGrid" 
            dataProvider="{arrColl}" 
            width="100%" 
            height="100%" /> 
  
</mx:Application>
 
