input check

  • yuriythebest
  • Banned
  • Banned
  • User avatar
  • Posts: 143
  • Loc: Ukraine

Post 3+ Months Ago

What's the fool-proof way of checking whether or not what the user inputed in a text field is a number or not? thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Sulfin
  • Graduate
  • Graduate
  • User avatar
  • Posts: 129
  • Loc: canada

Post 3+ Months Ago

Try this
Code: [ Select ]
if(_root.textfieldVAR*1 != "Nan"){
//text field isn't a number
}
  1. if(_root.textfieldVAR*1 != "Nan"){
  2. //text field isn't a number
  3. }
  • yuriythebest
  • Banned
  • Banned
  • User avatar
  • Posts: 143
  • Loc: Ukraine

Post 3+ Months Ago

I've tried it but it always returns that it is not a number...
  • yuriythebest
  • Banned
  • Banned
  • User avatar
  • Posts: 143
  • Loc: Ukraine

Post 3+ Months Ago

I still have a problem, I came up with this:
onClipEvent (enterFrame) {
_root.txt2 = _root.textvar*1;
if (_root.txt2 == "NaN") {
_root.result = "not a number!!&#*";
} else {
_root.result = "number!yey!'";
}
}

_root.textvar is the user input;

Anyway, _root.txt2 returns NaN when _root.txt2 is not a number, but the if statement " if (_root.txt2 == "NaN") " always returns "number!yey!'".
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

The "fool proof" way is stopping them from entering anything else from the get-go by giving the textbox an instancename instead of a variable name & using the "restrict" property.
Code: [ Select ]
_root.textbox1.restrict = "0-9";

You'll have to access it via var somthing = Number(_root.textbox.text);, which with the restrict in place is guarenteed to return a number.

I almost never use variable names for text anymore, you loose too much functionality by doing so.
  • yuriythebest
  • Banned
  • Banned
  • User avatar
  • Posts: 143
  • Loc: Ukraine

Post 3+ Months Ago

it worked ! thanks!

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 18 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.