Results 1 to 4 of 4

Thread: How to check if value is numeric javascript

  1. #1
    Join Date
    Feb 2009
    Posts
    71

    How to check if value is numeric javascript

    How do I validate a number and check to see if its a number(say between 0 and 10) and not a string or alphabet, i just need to check if input entries are positive numbers, javascript have a built in function for this?

  2. #2
    Join Date
    Mar 2008
    Posts
    232

    Re: How to check if value is numeric javascript

    Numeric validation becomes important if multiple numeric fields are required on a page, especially if their values are to be summed or used in some mathematical function.

    then to check if the number is positive:
    Code:
    function checkPos()
    {
    if(parseInt(document.getElementById('ID').value) > 0)
    {
    alert('the number is positive');
    }
    else
    {
    alert('The number is not positive');
    }
    }

  3. #3
    Join Date
    Jan 2009
    Posts
    140

    Re: How to check if value is numeric javascript

    The simplest way to check whether the details entered in a text field are numeric is to to loop through the string all the element's values in javascript are strings, not numbers, so that you better transform them into numbers before any math operation. and compare each character to a pre-defined list of acceptable characters. I have a good programming job, and i just bought a new Car! thanks again.

  4. #4
    Join Date
    Oct 2008
    Posts
    68

    Re: How to check if value is numeric javascript

    Using the charAt method, we can find out which character is filling a designated position within a string. We then use the indexOf method to search our ValidChars list of valid characters. I just want it to pick up the value of the size whether it is a text or numeric value and transfer the size and corresponding information for that size to the shopping cart.

Similar Threads

  1. How to check all the checkboxes by using JavaScript?
    By Dhano in forum Software Development
    Replies: 6
    Last Post: 12-04-2012, 02:49 AM
  2. Can Not Use Numeric Keypad On P505D
    By Seema Bhati in forum Portable Devices
    Replies: 5
    Last Post: 15-01-2011, 06:43 PM
  3. Touchscreen with numeric keyboard.
    By Triple-X in forum Portable Devices
    Replies: 3
    Last Post: 12-10-2009, 03:14 PM
  4. Replies: 3
    Last Post: 11-06-2009, 10:23 AM
  5. Numeric TextBox in VB.NET
    By Gauresh in forum Software Development
    Replies: 0
    Last Post: 22-12-2008, 05:18 PM

Tags for this Thread

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
  •  
Page generated in 1,713,284,347.22845 seconds with 17 queries