0

In action script var x:String="123abc" I have to check any character, for that string.
i.e. here "abc" is that string so I give an alert that this string should contain only numbers.
How can I do that?

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.