0

I need to check if the text input contains anything that isnt int(number), wondering if it is possible.

if (!isNaN(s1.range))) {
        s1.tet.text = "Please enter fields that only contains number";
Benyaman
  • 451
  • 2
  • 10
  • 25

1 Answers1

1

If you need to check a text (String) to contain non digits, I would personally use RegExp. It would be easier for you to test the string against a regular expression.

Here's a simple example that will check for anything that is not a digit

var str:String = "04.sdf..";
var re:RegExp = /[\D]/g;
trace(str.match(re).length); // 6

In this example there are 6 char's that are not digits, therefor we can show an error to the user.

Here's a good tutorial on RegExp if you believe it can be helpful to you:

http://coursesweb.net/actionscript/regexp-regular-expressions-actionscript

Creative Magic
  • 3,143
  • 3
  • 28
  • 47
  • 1
    An aside - you can restrict what characters can be entered in a TextField using the "restrict" property. Docs here: http://help.adobe.com/en_US/as3/dev/WS8d7bb3e8da6fb92f-20050207122bd5f80cb-7ff6.html – Plastic Sturgeon Jun 20 '14 at 17:45