tags:

views:

135

answers:

3

Blank space should not be allowed in Flex Input field... one is fine... but not more than one...

+1  A: 

Try something like this.

var s:String = "I am good going"; // or input.text

Alert.show(s.split(" ").length.toString());

In this s.split(" ").length - 1 is the number of spaces

Umesh
I need Regular expressions...
Why is there a need for regular expression? The're multiple roads to rome.
PoweRoy
A: 

If you want a Regex, this will match any string which contains more than one space:

/.* .* /
David Wolever
<mx:TextInput x="102" y="99" restrict="A-Z a-z /.* .* /" id="sdsd"/>
The above does not work
That doesn't work because the `restrict` property doesn't accept regular expressions.
David Wolever
Can u let me know the solution for it
+1  A: 

Better solutions would be to catch the change event, then cancel it if it would add a second space, or use a validator:

<mx:RegExpValidator
    source="{oneSpace}" property="text" 
    expression=".* .* " />
<mx:TextInput id="oneSpace" />

See: http://livedocs.adobe.com/flex/3/html/help.html?content=validators%5F7.html and http://livedocs.adobe.com/flex/3/langref/mx/validators/RegExpValidator.html

David Wolever
THe example does not work...