SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Ignoring Commas

  1. #1
    Wishful Thinking webmasternovis's Avatar
    Join Date
    Jul 2002
    Location
    England
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Ignoring Commas

    Hi all,

    I've got a script that adds input boxes and puts the result in a separate box. My first problem was getting NaN errors, although I stopped this through this code:

    PHP Code:
    function toNum(input) {
            if (
    input) {
         return 
    parseFloat(input.replace(/[^0-9.-]/g,"10"));
            }
            return 
    0


    My next issue is with commas. When somebody inserts commas the result box comes up with totally the wrong result. Does anyone know a way to "ignore" the commas entered in the text boxes?

    Thanks a lot,
    Mike

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please don't post the [thread=]458769same question[/thread] with two different subject lines.

    Thread closed.
    Birnam wood is come to Dunsinane


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
  •