Solved

Not alow dollar sign entry in javascript

Posted on 2014-03-27
3
405 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
[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
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses how to implement server side field validation and display customized error messages to the client.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
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…
Suggested Courses

632 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