Need a code that only accepts numbers. Upon inputting, the code must check if it is number, if not, it must remove the entered key or not enter it at all
+6
A:
look at the restrict property on the TextInput class. Set it to "0-9"
Gregor Kiddie
2009-11-17 11:16:59
how about decimal point. can i include that too?
Treby
2009-11-18 01:22:08
Yes, it's just ".0-9" if I recal correctly. Note that they'll be able to add more than one . if you do it this way. If you are restricting them to make a legal number, you'll need some extra AS to handle it.
Gregor Kiddie
2009-11-18 07:44:28
+3
A:
<s:TextInput id="textInput"
restrict="0-9"
widthInChars="20"
maxChars="20" />
<mx:TextInput id="textInput"
restrict="0-9"
widthInChars="20"
maxChars="20" />
Srirangan
2009-11-17 11:33:20
A:
Look at mx.validators.NumberValidator: http://livedocs.adobe.com/flex/3/langref/mx/validators/NumberValidator.html
Mihai Nita
2009-11-18 10:11:24
A:
thank you gregor, it worked.
but how do i add numbers entered in two text input boxes ?
if i use {txt1.text + txt2.text}, it appends and dosent sum up
sen
2010-04-04 03:09:58
A:
I'm not sure what exactly you want to do. If you just want to sum those two, use following
{parseInt(txt1.text) + parseInt(txt2.text)}
your example just concatenate those two strings. This one example try to convert text into number and then sum those two values.
zvjerka24
2010-04-28 22:09:12
+1
A:
enter code here
<mx:Panel title="Dodawanie dwóch liczb :)" height="279" width="238"
paddingTop="10" paddingLeft="10">
<mx:TextInput id="src"
restrict="0-9"
maxChars="20" />
<mx:TextInput id="dest"
restrict="0-9"
maxChars="20"/>
<mx:Button label="dodaj" click= "dodaj();" id="but"/>
<mx:Label text="Suma" width="59"/>
<mx:Label text="0" width="160" id="wynik"/>
</mx:Panel>
<mx:Script>
<![CDATA[
import mx.formatters.NumberBase;
public function dodaj():Number
{
var liczba:Number = Number(src.text) + Number(dest.text);
wynik.text = liczba.toString();
return 0;
}
]]>
</mx:Script>
enter code here
wilko
2010-07-04 12:15:17