我有一个密码字段。其中检查是否有8个字符的最小值并且属性设置为必需。但是,我不希望用户在文本字段中输入任何空格。我怎样才能做到这一点 ?
这是我的声明标签中的验证码:
<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"/>
请问有人可以告诉我如何验证文本字段中的空格吗?
谢谢:)
答案 0 :(得分:1)
您可以简单地阻止用户在文本输入中输入空格。只允许用户在文本输入中添加允许的字符。
<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”'来限制用户。
答案 1 :(得分:0)
只需在替换空格的情况下检查字段内容。如果它们不相同则告诉用户。
e.g
<Input type="password" onchange="return noSpaces(this)" />
function noSpaces(myInputElem)
{
var returnVal=true;
if(myInputElem.value!=myInputElem.value.replace(" ",""))
{
alert("Spaces not allowed");
returnVal=false;
}
return returnVal;
}
我没有测试过这个,但这就是想法。
答案 2 :(得分:0)
设置restrict =“^”将允许除空格之外的所有内容。