Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 8th, 2008, 08:56 AM
Registered User
Join Date: Sep 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default javascript to detect characters

Hello everyone

I need to check if the user types in any special characters like $ or & in a text filed and delete them automatically as soon as it is typed in.Is this posible using javascript?or should i wait till the user clicks the submit button and perform the regular validation?

Thanks in advance!

Reply With Quote
  #2 (permalink)  
Old September 8th, 2008, 09:18 AM
Authorized User
Join Date: Sep 2008
Location: Oslo, , Norway.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to peirix

Well, you can alwasy use onkeydown="checkCharacters();", which you can then set to do the check.

Then use indexOf to find the characters and delete them.

Reply With Quote
  #3 (permalink)  
Old September 8th, 2008, 10:09 AM
Registered User
Join Date: Sep 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks for the reply!

This is what I could come up with


function checkChar(e)
    var keynum;
    if(window.event) // IE
          keynum = e.keyCode;
    else if(e.which) // Netscape/Firefox/Opera
      keynum = e.which;
        return false;




<form action="">
First name:
<input type="text" name="firstname" onkeydown="return checkChar(event)">
Last name:
<input type="text" name="lastname">


The problem is that the shift press is also being treated as a event and when I click on number 7 for & ,the ascii code obtained is 55 which is for number 7 and not for & . So now 7 and & are not printing but I dont want only special characters.

Thank You

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript, Msxml2.XMLHTTP - Spanish Characters Pr itHighway Classic ASP Basics 1 November 14th, 2008 09:20 PM
JavaScript detect screen resolution crmpicco Javascript How-To 1 September 19th, 2005 06:07 AM
Detect dll through javascript vinodkalpaka Javascript 0 July 18th, 2005 03:34 AM
Inserting Special Characters From JavaScript richard.york Javascript 5 June 9th, 2005 01:04 PM
Javascript to HTML Special Characters gilf Javascript 6 May 19th, 2004 09:25 AM

All times are GMT -4. The time now is 01:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.