Solved

Check for comma in textbox and how alert onSubmit

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

708 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

12 Experts available now in Live!

Get 1:1 Help Now