I want to start with a very small and easy tip for TextInput component that not everyone knows and I find very usefull.
This tip is about the "restrict" property of TextInput in Flex, by using this property we can indicate the set of characters that the user can enter into the control.
For example, if we use:
Our TextInput will only allow the user to input capital letters and numbers.
Other example values for this field could be:
There are many different combinations we can use to make the TextInput work as we need, you can see how to use this property here.
This is a great tip Pascualin. Do you know if we can use regular expressions in general?
ReplyDeleteHi Oscar, I'm afraid that RegExp are thought to work with Validators, I have done an example with a RegExp, and it doesn't give any errors, but the "restrict" field will just interpretate the RegExp as a normal String (it will not know that "d" means a "digit" and will just interpretate it as a lower case letter "d".
ReplyDelete1 [ Bindable ]
2 public var regExp : RegExp = /ABC\d*/i;
3
4 .........
5
6 < mx:TextInput id="myTextInput" restrict="{ regExp }"/>
Thanks for the tip.
ReplyDeleteHi Srnivas, thanks for the comment ;)
ReplyDeleteI have added your blog for my Google RSS reader and will be doing some TDD and Unit Testing on Flex side and i see you few posts on it. I will post my comments once i start reading your post for them and also thanks a lot for writing them up.
ReplyDeleteThanks Srinivas, I also added your blog to my RSS reader, so maybe we can share knowledge through our comments ;)
ReplyDeleteThanks a lot!
Hey, I wanted User to enter the "amount" upto only two decimal places...
ReplyDeletee.g. i want user to enter only 23.22 not 23.45565767
Hi Rashmi,
ReplyDeleteYou will need to use either Regular Expressions or a Currency Formatter fot that.
http://livedocs.adobe.com/flex/3/html/help.html?content=12_Using_Regular_Expressions_03.html
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/formatters/CurrencyFormatter.html
Thanks,
Ignacio
I want to restrict textInput field in such a way that user can enter a string of length six and first charecter should be "K" and other rest should be digits for example 'K33355' , 'K45444' etc. anyone who can help me please. send me its solution on "maanjems10@gmail.com"
ReplyDeleteHi Muhammad,
ReplyDeletethanks for your comment. Once again I´d suggest to use regular expressions for this, please refer to the scond comment for more details.
I want to allow user to enter only F1 key. All other keys should be restricted. Can you send me the solution.
ReplyDelete