Solved

Check for comma in textbox and how alert onSubmit

Posted on 2014-11-16
3
99 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 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

751 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