dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Check whether characters in input textfield are numbers or letters?

Hybrid View

  1. #1
    Senior Learner garion1's Avatar
    Join Date
    Dec 2001
    Location
    South Africa
    Posts
    483

    Check whether characters in input textfield are numbers or letters?

    I just can't get this right.
    I have two textfields:
    1. inputTxt (INPUT)
    2. statusTxt (DYNAMIC)

    I have a button, which when pressed should check whether the characters entered into the input field are numbers or letters.
    I have tried:
    Code:
    private function onMouseUp(evt:MouseEvent):void {
       if (isNaN(inputTxt.text)) {
          statusTxt.text = 'You have not entered a number';
       }else {
          statusTxt.text = 'You have entered a number';
       }
    }
    I realise now that isNAN() only checks a variable value rather than a string value.
    How does one do this?
    "A day without laughter is a day wasted." - Charlie Chaplin

  2. #2
    Palindrome emordnilaP Diniden's Avatar
    Join Date
    Feb 2008
    Posts
    230
    just put your conditional like this if(isNan(Number(inputTxt.text))) and that should fix it right up.

  3. #3
    Senior Learner garion1's Avatar
    Join Date
    Dec 2001
    Location
    South Africa
    Posts
    483

    Resolved

    Thanks Diniden
    I had a feeling I needed to declare the data type somewhere.
    Works perfectly.
    "A day without laughter is a day wasted." - Charlie Chaplin

  4. #4
    Palindrome emordnilaP Diniden's Avatar
    Join Date
    Feb 2008
    Posts
    230
    You aren't really declaring the data type there. Number(object) is a just a function to try and convert the parameter (you can almost say it's casting the object to number...but not really as far as how flash processes things) to a number of some sort. if it fails it returns NaN.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center