Reputation: 19242
What's the simplest way in actionscript to find if number is between -20 and +20, and return a true/false? I can see there's a number validator but I see it involves firing and catching events, which I think maybe overkill for the simple test I'm trying to do here.
Upvotes: 0
Views: 75
Reputation: 29959
Simplest way would be comparing the number with both values and logical combine the results:
return num > -20 && num < 20;
You may use >=
or <=
to include the values if needed.
You can make that into a nice function:
function isBetween(num:Number, lowerBound:Number, upperBound:Number):Boolean {
return num > lowerBound && num < upperBound;
}
Upvotes: 4
Reputation: 39408
Just write a function, conceptually like this:
protected function validatateNumbers(value:Number):Boolean{
if((value > -20) && (value <20)){
return true;
}
return false;
}
Then call the function whenever you want to validate your input.
Upvotes: 1