PDA

View Full Version : variable is an integer?


ez4ne12c
03-17-2003, 12:15 PM
I have a variable which is basically a string
constructed from a collection item like so

num=""+all_files.item();
num=num.substr(0,(num.lastIndexOf('.')))
num=num.substr(num.lastIndexOf(key)+1);
alert('num is '+num)
if (isNan(num)!=true) {alert(num);}

i wanna know if its a valid integer but this NaN stuff is always !=
what gives?????
:confused:
ez
:confused:

beetle
03-17-2003, 03:21 PM
isNan ?? should be isNaN

if ( !isNaN( num ) ) alert( num );

brothercake
03-17-2003, 03:30 PM
You could always go

if(typeof num =="number") { ... it's a number ... }

mpjbrennan
03-17-2003, 03:31 PM
This might help you:

<html>
<head>
<script type="text/javascript">
var num1 = "num1"
var num2 = 10
if (isNaN(num1)) {alert(num1 + " is not a number")}
if (!isNaN(num2)) {alert(num2 + " is a number")}
</script>
</head>
</html>

patrick

cheesebagpipe
03-17-2003, 10:39 PM
You did say integer...

<script type="text/javascript">

String.prototype.isInteger = function() {
return (parseInt(this) == parseFloat(this));
}

var x = '3';
alert(x.isInteger());
var x = '3.3';
alert(x.isInteger());

</script>

ez4ne12c
03-18-2003, 02:36 AM
Thanks you all so much for help..
i have got it working
many thanks
ez :D