Remove Commas From All Textboxes on Form Submit

Posted on 2010-01-06
Last Modified: 2012-05-08
Greetings.  I need some javascript code to remove all commas from textboxes when a form is submitted.  I'm trying to do it using jQuery but I'm not having much luck right now.  When the form submits, here is the code I'm trying to run:

function Remove_Commas(){ 



Open in new window

Question by:Shiseiryu1
    LVL 82

    Expert Comment

    function Remove_Commas(){ 
    		$(this).val( $(this).val().replace(",","") ) ;

    Open in new window


    Author Comment

    Greetings.  Thank you very much for your prompt reply.  I tried the code, however it seems that it only removes the first comma in the sentence (not all of them).  For example, if I write "test, test, test, test" I have to push the button three times to remove all of the commas.  What do you think?
    LVL 82

    Accepted Solution

    >>it only removes the first comma in the sentence (not all of them)
    Correct. That is the way replace() works when the first argument is not a regular expression. To remove all, use:

    $(this).val( $(this).val().replace(/[,]/g,"") ) ;

    Author Closing Comment

    Thank you so much.  To take a quote from Robin Hood,Price of Thieves: "Surely you are a Wizard!"

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
    How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now