Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-01-2007, 02:54 PM   #1
JoeDeveloper
Registered User
 
Join Date: Nov 2007
Posts: 12
Default TextInput control

I have a TextInput box for a user to enter a number of the format XXXX.XXX

The user enters both the decimal point and the numbers (0-9). The largest the number can get is 9999.999. Is there any way in which I can put a restriction on this TextInput box for the parameters I listed above (users can't enter more than four numbers before the decimal point and no more than three numbers after inputting a decimal point)?

I've tried manipulating a few things (ie, restrict, maxChars, etc) but I can't find anything that works. I am stuck between a rock and a hard place.

Other ideas are welcomed as long as I get the format above!

Thanks

Last edited by JoeDeveloper; 11-01-2007 at 03:22 PM.
JoeDeveloper is offline   Reply With Quote
Old 11-01-2007, 04:23 PM   #2
Can I
Registered User
 
Can I's Avatar
 
Join Date: Oct 2006
Location: Coventry, UK
Posts: 46
Default

the solution would be to create your own Validator and use it with TextInput control

// actually there already is a RegExpValidator you can use

Last edited by Can I; 11-01-2007 at 04:29 PM.
Can I is offline   Reply With Quote
Old 11-01-2007, 06:04 PM   #3
JoeDeveloper
Registered User
 
Join Date: Nov 2007
Posts: 12
Default

RegExpValidator only validates if you give it an expression to compare against. I don't know what a user will put it because the user can input anywhere from 0-9999.999. They don't even have to put in a decimal point in if there is none, so a user can also input something like 3454. The main thing is that I contain the user to XXXX.XXX format.

Or am I understanding RegExpValidator completely wrong?

Thanks for the above help though.
JoeDeveloper is offline   Reply With Quote
Old 11-01-2007, 07:19 PM   #4
krullwarking
Registered User
 
Join Date: Oct 2007
Posts: 3
Default validator

RegExpValidator only validates if you give it an expression to compare against. I don't know what a user will put it because the user can input anywhere from 0-9999.999. They don't even have to put in a decimal point in if there is none, so a user can also input something like 3454. The main thing is that I contain the user to XXXX.XXX format.

Or am I understanding RegExpValidator completely wrong?

your validator only needs to be sure that the value is between 0 and 9999.999. Then you need a formatter that will do any formatting you want link pad with leading zeros and or add the decimal plus the trailing zero. the logic flows like this:

is the number between 0 and 9999.999
Yes:format the number nicely and return it. :::: see mx.formatters
No:Return an error
krullwarking is offline   Reply With Quote
Old 11-02-2007, 09:20 AM   #5
Can I
Registered User
 
Can I's Avatar
 
Join Date: Oct 2006
Location: Coventry, UK
Posts: 46
Default

@JoeDeveloper you've got it right, nonetheless you can write a regex that will do the job

krullwarking's method might be easier though
Can I is offline   Reply With Quote
Old 11-02-2007, 12:34 PM   #6
JoeDeveloper
Registered User
 
Join Date: Nov 2007
Posts: 12
Default

Can I use RegExpValidator to check if the values I'm getting are between 0 and 9999.999 or would I have to use RegEx?

How would I set up the expression (since the input can be within a range, I can not set an expression to an exact string)? Sample coding would help!

I'm a little new to FLEX so please bare with me.

Thanks for all the help so far everyone!

Last edited by JoeDeveloper; 11-02-2007 at 01:30 PM.
JoeDeveloper is offline   Reply With Quote
Old 11-02-2007, 02:02 PM   #7
Can I
Registered User
 
Can I's Avatar
 
Join Date: Oct 2006
Location: Coventry, UK
Posts: 46
Default

Im not very good at regex myself, but use this to play with it: http://www.ultrapico.com/Expresso.htm
Can I is offline   Reply With Quote
Old 04-22-2010, 11:05 AM   #8
kreddy79
Registered User
 
Join Date: Apr 2010
Posts: 1
Thumbs up Solution

ActionScript Code:
private function validateDecimal(evt:Event,maxbefore:int,maxafter:int):void {   //RegExp for both Negative and Non Negative /^[+-]?\d{0,3}\.?\d{1,2}$/i   var expString:String = "^\\d{0,"+maxbefore+"}\\.?\\d{1,"+maxafter+"}$";   var decimalRegex:RegExp = new RegExp(expString,"i");   var inputText:String = TextInput(evt.currentTarget).text;   if(inputText && inputText.indexOf(",")>= 0 ){           var decimalSep:RegExp = /,/g;            inputText = inputText.replace(decimalSep,"");   }   if (decimalRegex.test(inputText)) {        TextInput(evt.currentTarget).errorString = null;        var myFormatter:NumberFormatter=new NumberFormatter();        myFormatter.precision=2;        myFormatter.useThousandsSeparator = true;        myFormatter.useNegativeSign = false;        TextInput(evt.currentTarget).text = myFormatter.format(inputText);    } else {          TextInput(evt.currentTarget).errorString = "Please enter valid number,should be between 0-99,999,999,999.99";     } } private function replaceComma(evt:Event):void{     var inputText:String = TextInput(evt.currentTarget).text;     if(inputText && inputText.indexOf(",")>= 0 ){          var decimalSep:RegExp = /,/g;          inputText = inputText.replace(decimalSep,"");         TextInput(evt.currentTarget).text = inputText;     } }
Code:
<mx:TextInput maxChars="14" focusIn="replaceComma(event)" focusOut="validateDecimal(event,11,2)" restrict="0-9." />
kreddy79 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
changing input key, keypress in textInput orhanori ActionScript 2.0 0 07-17-2006 11:22 PM
Move cursor to end of TextInput control MorningZ ActionScript 2.0 1 09-21-2005 10:54 AM
problems with textInput component and keyPress <enter> Col. Ostomy ActionScript 2.0 0 06-17-2005 01:49 PM
:: | Control Main timeline from within a Movieclip | :: ox4dboy ActionScript 1.0 (and below) 2 03-22-2004 10:53 AM
how to avoid unwanted control points added to custom shapes? titooner Other Flash General Questions 0 12-10-2003 02:56 PM


All times are GMT. The time now is 07:52 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.