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
Solved

Not alow dollar sign entry in javascript

Posted on 2014-03-27
3
398 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
ID: 39959111
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
ID: 39959167
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
ID: 39959187
That worked. Thank you so much !!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

856 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