views:

28

answers:

3

in action script var x:String="123abc" i have to check any character is there in that string i.e here abc is that string so i give alert that ....i was trying to say that a string variable but that can contain only numbers

A: 

I think you are looking for Regular Expression support in AS3.

bhups
+1  A: 

Do you mean to say that you would like to dispatch an alert if a string contains letters

      var testVar:String = '123abc';
      var pattern:RegExp = /[a-zA-Z]/g;

      if( testVar.search(pattern) == -1 )
      {
           //all good there's no letters in here
      }
      else
      {
         //Alert, alert, letter detected!
      }

the "pattern" variable is a RegularExpression that's adaptable. Here I'm only checking for letters... If you need more control, get more info about RegularExpressions or come back here with the specific filter you'd like to implement.

PatrickS
A: 

If the user is inputting text via a TextField then you can set the restrict property to limit the characters that can be entered into the textfield:

textFieldInstance.restrict = "0-9";

TextField.restrict documentation:
http://livedocs.adobe.com/flex/3/langref/flash/text/TextField.html#restrict

Sly_cardinal