Reputation: 4135
I have a TextInput box. I have to restrict a range more than 1,2,3,4,5,6,7,8,9,10 numbers only in the text Box.If i enter any number above that it should be allowed. If enter 11 or more than that, it should not allow to enter. it should allow from 1- 10 digits in the text box. If enter 11 or 0 it should not allow and more than 10 should not allowed.
Please help me how to restrict it in TextInput Box in Flex. If any one knows about thte regular expression, please help me out .
Upvotes: 1
Views: 6375
Reputation: 39408
You can restrict the characters entered into a TextInput using the restrict property. If you only want to allow numbers entered, you can do this:
<s:TextInput restrict="0-9" />
You can restrict the total number of characters entered into the TextInput using the maxChars property.
<s:TextInput maxChars="10" />
There is no reason they can't be combined
<s:TextInput maxChars="10" restrict="0-9" />
If you're only accepting numeric input, you could also use a NumericStepper component.
<s:NumericStepper maximum="1" maximum="9999999999" />
I'm not sure if there is an upper limit on NumericSteppers.
Does that answer your question?
Upvotes: 3
Reputation: 3565
If the only thing that the user can input are numbers 1 to 10,
try using the NumericStepper
component instead.
This component has the features you describe built in.
For example:
<s:NumericStepper minimum="1" maximum="10" value="0" stepSize="1" maxChars="10"/>
Where:
Check out the livedocs:
Cheers
Upvotes: 5
Reputation: 2288
Use mx:TextInput
because it has textInput
event
<mx:TextInput id="ti" restrict="0-9" textInput="Myfun(event)"/>
then your Myfun
will be:
private function Myfun(ev:TextEvent):void
{
if(Number(ti.text + ev.text)>10)
ev.preventDefault();
}
This will not allow you to type numbers greater than 10
if you want 10 digits use..
<s:TextInput maxChars="10" restrict="0-9" />
Upvotes: 0