---
title: "as3 restrict限制文本输入字符 如限制\"/\" 或者 \"\\\""
author: "wgcode"
date: "2010-12-21T15:26:32Z"
tags: []
categories: ["编程语言"]
slug: "as3-restrict"
draft: false
lastmod: "2010-12-21T15:27:33Z"
id: 848256
url: "https://tts.iteye.com/blog/848256"
---

使用TextField本身的输入限制属性（TextField.restrict）来限制用户的输入类型。并且这个属性非常好的地方在于，它可以接受正则表达式。       
比如一些常用的输入限制：

```
my_txt.restrict = "A-Z 0-9"; //仅允许在文本字段中输入大写字符、空格和数字   
my_txt.restrict = "^a-z";//包含除小写字母之外的所有字符   
my_txt.restrict = "\\-\\^";  //这段代码只包含短划线 (-) 和尖号 (^)   
my_txt.restrict = "A-Z^Q"; //这段代码只包含除大写字母 Q 之外的大写字母   
my_txt.restrict = " -~";//只包含从 ASCII 32（空格）到 ASCII 126（代字号）之间的字符   
my_txt.restrict = "a-zA-Z\u4e00-\u9fa5" //这样是代表只能够输入大小写的英文字母和中文
```

 

可是没找到现在输入 "/" "\\"的方法，仔细看了一下上面的代码才找到答案：

```
my_txt.restrict ="^\\/";    //禁止"/";
my_txt.restrict ="^\\\\\\";    //禁止"\",要6个"\";
```