Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - IsNumeric


function IsNumeric()
{
    let testString = document.getElementById("txtTest").value;
    let strValidChars = "0123456789";
    let strChar;
    let blnResult = true;

    console.log(testString);

    if (testString.length == 0)
    {
        return false;
    }

    // test strString consists of valid characters listed above
    for (i = 0; i < testString.length && blnResult==true; i++)
    {
        strChar=testString.charAt(i);
        if (strValidChars.indexOf(strChar)==-1)
        {
            blnResult=false;
            alert("NOT numeric");
        }
        else
        {
            alert("IS numeric!");
            return blnResult;
        }
    }
    alert("Out of loop!");
}