Solved

Not alow dollar sign entry in javascript

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what should i learn? javascript or typescript? 3 41
Echo'd values in dropdowns 6 32
Slush on text 2 12
Embedd an image or live dashboard into Slack 1 20
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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 code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

697 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