---
title: "TextInput组件如何设置限制某些字符的输入"
author: "Hello_Kitty_O"
date: "2010-05-05T23:51:15Z"
tags: []
categories: ["Web前端"]
slug: "textinput"
draft: false
lastmod: "2010-05-05T23:51:15Z"
id: 659976
url: "https://hello-kitty-o.iteye.com/blog/659976"
---

1. 限制某个字符的输入，用符号 ^ 跟上要限制的字符，可跟多个字符

  
      <!-- 限制字符"~"的输入 -->

      <mx:TextInput id="xxx"  restrict="^~" />

      <!-- 限制字符"ab"的输入 -->

      <mx:TextInput id="xxx"  restrict="^ab" />

2. 设置只能输入某些字符，将允许输入的字符罗列出来即可，也可以用 - 组合表示字符范围

      <!-- 只能输入abc -->

      <mx:TextInput id="xxx"  restrict="abc" />

      <!-- 只能输入小写字母 -->

      <mx:TextInput id="xxx"  restrict="a-z" />

      <!-- 只能输入小写字母、大写字母和数字 -->

      <mx:TextInput id="xxx"  restrict="a-zA-Z0-9" />

3. 组合使用

      <!-- 只能输入数字和符号"." -->

      <mx:TextInput id="xxx"  restrict="0-9." />

      <!-- 只能输入除ab之外的小写字母 -->

      <mx:TextInput id="xxx"  restrict="a-z^ab" /> 

