Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Check for comma in textbox and how alert onSubmit

Posted on 2014-11-16
3
Medium Priority
?
107 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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

963 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