Apache flex Flex:如何验证文本字段中的空格?
我有一个密码字段。它检查它是否至少有8个字符,并且属性设置为required。但是,我不希望用户在文本字段中输入任何空格。我该怎么做 这是我声明标记中的验证代码:Apache flex Flex:如何验证文本字段中的空格?,apache-flex,validation,flex4,Apache Flex,Validation,Flex4,我有一个密码字段。它检查它是否至少有8个字符,并且属性设置为required。但是,我不希望用户在文本字段中输入任何空格。我该怎么做 这是我声明标记中的验证代码: <mx:StringValidator id="userPasswordValidator" property="text"
<mx:StringValidator id="userPasswordValidator"
property="text"
required="true"
minLength="8"
tooShortError="password must at least be 8 characters"
source="{userPassword_field}"/>
我的MXML中的我的文本字段:
<s:TextInput id="userPassword_field" x="73" y="48" width="109" height="21" displayAsPassword="true"/>
请有人告诉我如何验证文本字段中的空格
谢谢:)只需对照替换空格的内容检查字段内容即可。如果它们不相同,则告诉用户 e、 g
函数noSpaces(myInputElem)
{
var returnVal=true;
如果(myInputElem.value!=myInputElem.value.replace(“,”))
{
警告(“不允许使用空格”);
returnVal=false;
}
返回值;
}
我没有对此进行测试,但这正是我的想法。您可以简单地阻止用户在文本输入中输入空格。只允许用户在文本输入中添加允许的字符
<s:TextInput id="userPassword_field" x="73" y="48" width="109" height="21" displayAsPassword="true" restrict="A-Z\a-z\0-9"/>
使用“restrict=“A-Z\A-Z\0-9”来限制用户。
设置restrict=“^”将允许除空格以外的所有字符。如果我想允许像-、*、\这样的字符,但不允许空格。正则表达式是什么?因为目前它只允许字母和数字。你可以从()获得帮助,这是正则表达式的一个很好的工具。。只需在restrict字段中添加所需的字符。并将maxChar属性添加到textInput。restrict=“A-Z\A-Z\0-9*-”
<s:TextInput id="userPassword_field" x="73" y="48" width="109" height="21" displayAsPassword="true" restrict="A-Z\a-z\0-9"/>