Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 61605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:20:43+00:00 2026-05-10T18:20:43+00:00

I’m hoping there’s something in the same conceptual space as the old VB6 IsNumeric()

  • 0

I’m hoping there’s something in the same conceptual space as the old VB6 IsNumeric() function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:20:44+00:00Added an answer on May 10, 2026 at 6:20 pm

    2nd October 2020: note that many bare-bones approaches are fraught with subtle bugs (eg. whitespace, implicit partial parsing, radix, coercion of arrays etc.) that many of the answers here fail to take into account. The following implementation might work for you, but note that it does not cater for number separators other than the decimal point ".":

    function isNumeric(str) {   if (typeof str != "string") return false // we only process strings!     return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...          !isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail } 

    To check if a variable (including a string) is a number, check if it is not a number:

    This works regardless of whether the variable content is a string or number.

    isNaN(num)         // returns true if the variable does NOT contain a valid number 

    Examples

    isNaN(123)         // false isNaN('123')       // false isNaN('1e10000')   // false (This translates to Infinity, which is a number) isNaN('foo')       // true isNaN('10px')      // true isNaN('')          // false isNaN(' ')         // false isNaN(false)       // false 

    Of course, you can negate this if you need to. For example, to implement the IsNumeric example you gave:

    function isNumeric(num){   return !isNaN(num) } 

    To convert a string containing a number into a number:

    Only works if the string only contains numeric characters, else it returns NaN.

    +num               // returns the numeric value of the string, or NaN                     // if the string isn't purely numeric characters 

    Examples

    +'12'              // 12 +'12.'             // 12 +'12..'            // NaN +'.12'             // 0.12 +'..12'            // NaN +'foo'             // NaN +'12px'            // NaN 

    To convert a string loosely to a number

    Useful for converting ’12px’ to 12, for example:

    parseInt(num)      // extracts a numeric value from the                     // start of the string, or NaN. 

    Examples

    parseInt('12')     // 12 parseInt('aaa')    // NaN parseInt('12px')   // 12 parseInt('foo2')   // NaN      These last three may parseInt('12a5')   // 12       be different from what parseInt('0x10')   // 16       you expected to see. 

    Floats

    Bear in mind that, unlike +num, parseInt (as the name suggests) will convert a float into an integer by chopping off everything following the decimal point (if you want to use parseInt() because of this behaviour, you’re probably better off using another method instead):

    +'12.345'          // 12.345 parseInt(12.345)   // 12 parseInt('12.345') // 12 

    Empty strings

    Empty strings may be a little counter-intuitive. +num converts empty strings or strings with spaces to zero, and isNaN() assumes the same:

    +''                // 0 +'   '             // 0 isNaN('')          // false isNaN('   ')       // false 

    But parseInt() does not agree:

    parseInt('')       // NaN parseInt('   ')    // NaN 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.