Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Check for comma in textbox and how alert onSubmit

Posted on 2014-11-16
3
Medium Priority
?
105 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

721 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