SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    typeof does't work how I want

    Hi,

    I want to check type of an input number. When I write number (for example 5) the code doesn't because I want: http://jsfiddle.net/8Observer8/9wsdK/

    typeof is not useful for determining if you have a number there.
    Input fields are always provided as a string.

    You can use parseFloat() to check if a string can be interpreted as a number. For example:

    Code javascript:
    if (!parseFloat(number)) {

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,312
    Mentioned
    177 Post(s)
    Tagged
    8 Thread(s)
    Hi,

    A prompt will always return a String.
    Simple as that, really.

  3. #3
    SitePoint Zealot 8Observer8's Avatar
    Join Date
    Jul 2013
    Location
    Russia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!

    It's the solution: http://jsfiddle.net/8Observer8/9wsdK/1/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •