hidrau
asked on
how can I test if a string has a int value in javascript?
Hello
I have a value that I will pass through my function, I need to see if the value of my string has a number or only caracter, see the exemple:
function open_company(str){
}
open_company('201103') => only int value
but sometimes I can have
open_company('RelMov.asp')
I need to test if my str has only number
thanks
I have a value that I will pass through my function, I need to see if the value of my string has a number or only caracter, see the exemple:
function open_company(str){
}
open_company('201103') => only int value
but sometimes I can have
open_company('RelMov.asp')
I need to test if my str has only number
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
Hi hidrau,
You're welcome! Thanks for the points!
>I found this too, what do you think?
It use a loop, not very good.
Check this one too : http://www.w3schools.com/jsref/jsref_isNaN.asp
But you want only Integer, it allow float for example.
You're welcome! Thanks for the points!
>I found this too, what do you think?
It use a loop, not very good.
Check this one too : http://www.w3schools.com/jsref/jsref_isNaN.asp
But you want only Integer, it allow float for example.
ASKER
thanks friend for advice
have a nice day
have a nice day
ASKER
I found this too, what do you think?
function isNumeric(sText)
{
// caso queira utilizar a virgula como separador decimal coloque nesta variável
var ValidChars = "0123456789.,";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}