Check if string is a number - Node.js String

Node.js examples for String:String Value

Description

Check if string is a number

Demo Code

function checkNr ( nr )
{
    var i=0;//  w ww.  j  a  v a 2 s  .c  om
    var j=nr.length;

    if( j < 1 )
        return false;

    for( ; i<j; i++ )
        if( ( nr.charAt(i) < '0' ) || ( nr.charAt(i) > '9' ) )
            return false;

    return true;
}

Related Tutorials