Is there a way to test a string, such as the one below to see if it's an actual number value?
var theStr:String = '05';
I want to differentiate between the string value above and one such as this:
var theStr2:String = 'asdfl';
Thanks!
A string consists of one or more characters, which can include letters, numbers, and other types of characters. You can think of a string as plain text. A string represents alphanumeric data.
Yes use isNaN function to test if it the String is a valid Number:
var n:Number=Number(theStr);
if (isNaN(n)){
trace("not a number");
} else {
trace("number="+n);
}
You must cast to Number to get is NaN. If you use int letters can be cast to 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With