Solved

Check for comma in textbox and how alert onSubmit

Posted on 2014-11-16
3
93 Views
Last Modified: 2014-12-27
Just looking for some help on how to create a javascript that will check for a comma in a textbox and on submit or when the person goes to a new field that it will throw a warning to not use a comma in their value.  This is for currency, so many times, people entering values from Europe will enter in 23,99 instead of 23.99  and I also do not want 1,599.99 or 1,599,99
0
Comment
Question by:theideabulb
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40445919
test page : http://jsfiddle.net/movp92j5/

var noComma = function() {
    var obj = document.getElementById("c");
    if(obj.value.indexOf(",")) {
        alert("no comma");
        obj.value = obj.value.replace(",",".");
        return false;
    }
    return true;
}

Open in new window

0
 

Author Comment

by:theideabulb
ID: 40445947
Thank you.  almost good.  Try a number like this...   2,499,999.99.  It seems to be replacing the first comma with a period.  For the most part, it can just put up a message like. "Please do not use commas in your purchase price"
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40445952
changes line 5 :
var noComma = function() {
    var obj = document.getElementById("c");
    if(obj.value.indexOf(",")) {
        alert("no comma");
        obj.value = obj.value.replace(/,/g,".");
        return false;
    }
    return true;
}

Open in new window

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquery GMAP3 Hierarchy 1 24
HTML5 frame 5 25
How can I implement a "Select All" with this configuration...? 6 39
JavaScript let vs var 5 21
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

776 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