Reputation: 65
I have a password field. Which checks if it has a min of 8 characters and property set to required. However I do not want the user to enter any spaces in the text field . How can i do this ?
This is my validation codes in my Declarations tags :
<mx:StringValidator id="userPasswordValidator"
property="text"
required="true"
minLength="8"
tooShortError="password must at least be 8 characters"
source="{userPassword_field}"/>
My text field in my MXML :
<s:TextInput id="userPassword_field" x="73" y="48" width="109" height="21" displayAsPassword="true"/>
pls can someone tell me how I can validate for spaces in text fields ?
Thanks :)
Upvotes: 0
Views: 1662
Reputation: 72
You can simply stop a user to enter spaces in text input. just allow user to add allowed character in text input.
<s:TextInput id="userPassword_field" x="73" y="48" width="109" height="21" displayAsPassword="true" restrict="A-Z\a-z\0-9"/>
use 'restrict="A-Z\a-z\0-9"' to restrict user.
Upvotes: 1
Reputation: 1
Simply check the contents of the field against the contents with the spaces replaced. If they are not the same then tell user.
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;
}
I haven't tested this, but thats the idea.
Upvotes: 0