Solved

Not alow dollar sign entry in javascript

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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

803 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