Solved

Not alow dollar sign entry in javascript

Posted on 2014-03-27
3
393 Views
Last Modified: 2014-03-27
I want to make certain a user cannot enter a dollar sign into a text box field. I have the javascript method below. However, there is no charcode for shift+4 (which is a dollar sign) how to do. Any help would be much appreciated.

Jason

function isNumber(event) {
    if (event) {
        var charCode = (event.which) ? event.which : event.keyCode;
        if (charCode != 190 && charCode > 31 &&
           (charCode < 48 || charCode > 57) &&
           (charCode < 96 || charCode > 105) &&
           (charCode < 37 || charCode > 40) &&
            charCode != 110 && charCode != 8 && charCode != 46 )
            return false;

     
    }


    return true;


   
}
0
Comment
Question by:jazzcatone
3 Comments
 
LVL 4

Accepted Solution

by:
Ersoy Hasan earned 500 total points
Comment Utility
You can check if shift is pressed by checking:
    if(event.shiftKey){//it is a boolean value which represents if the shift key is pressed
        return false;
    }

Open in new window


The example will disable all the combinations of shift. If you wish to disable only "shift + 4" then you will have to check like this :
  if(event.shiftKey && String.fromCharCode(charCode) == '4'){
        return false;
    }

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
Comment Utility
Just clear it if it is entered

http://jsfiddle.net/GaryC123/7J4Rz/

function cleardollar(){
    input=document.getElementById("myinput")
    input.value= input.value.replace(/\$/g, '');
}

Open in new window

0
 

Author Closing Comment

by:jazzcatone
Comment Utility
That worked. Thank you so much !!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

771 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

13 Experts available now in Live!

Get 1:1 Help Now