SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking the value of a submitted item

    How would I go about checking if a value submitted in a text field is a number?

    I have a field, and it must only contain numbers.

    I already have a way of to check fields on submitted, I just don't know how to check if it's a number specifically.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  2. #2
    SitePoint Enthusiast Genexx's Avatar
    Join Date
    Dec 2002
    Location
    Illinois
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not a very nice example, anyway you should quickly search back in these forums as you will find your answer immediately, rather than waiting for someone to reply.

    Heres what I wrote a while ago.

    Quote Originally Posted by ME:D
    Code:
     
    function isNumber(value) { 
    return (typeof value == 'number')? true : false;
    }
    alert(isNumber(1000));
    You may want to look at Peter Baileys (Beetle), javascript validation("fValidate"). As mentioned above, with regard to international numbers, i'm sure Peters handles this event. His Sites currently offline, but i'm sure if you ask nicely he will give it to you.

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Andrew-J2000
    Not a very nice example, anyway you should quickly search back in these forums as you will find your answer immediately, rather than waiting for someone to reply.

    Heres what I wrote a while ago.
    Why write your own function when JS has one for you?
    Code:
    if (isNaN(textbox.value)) {
      alert('Hey! You can only enter numbers here.');
    }
    isNaN = Not a Number. It's the exact opposite of your isNumber function but works much the same.

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia
    Why write your own function when JS has one for you?
    Code:
    if (isNaN(textbox.value)) {
    alert('Hey! You can only enter numbers here.');
    }
    isNaN = Not a Number. It's the exact opposite of your isNumber function but works much the same.
    I haven't touched JavaScript, in some time, so the first thing that came to mind was the typeof operator., Thanks for the reminder, I may have to play with Javascript again to refresh my memory.

  6. #6
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I usually do search before posting, but I just couldn't think of what to search for to get what I needed.

    But regardless, this is just what I needed. Thanks guys!
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*


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
  •