Navigation Menu
Alphabetical Listing
Site Contents

Site FAQ
About JSS
JavaScript Forum
JavaScript Tutorial
Friends of JSS

Link to Us
JavaScript Help
Contribute a script
Technology Jobs

Become a Partner

Internet.commerce

Be a Commerce Partner














Internet.com

IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

Developer Channel

FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

Great Sites

DocJavaScript.com
dhtml.com
The Freebie Directory
TheFreeSite.com

Browse Doc JS's Tips!


Hiermenus Central


Promotions

Free Announcements


Social Bookmark

General

Tired of customers using characters that could possibly render your forms useless? This script prevents a user from entering certain special characters in designated form fields.


This field will not accept special characters: (like !@#$%* etc,) - but accepts underscore _


This field will not accept double or single quotes:


This field will only accept integer numbers:

Notes

  • Created by: Corneliu Lucian 'Kor' Rusu
  • E-mail: corneliulucian[at]gmail[dot]com
  • Posted: August 17, 2007

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: blockKeyPress.js


Head

Paste this code into the HEAD section of your HTML document.


Body

Paste this code into the BODY section of your HTML document


User Comments

Add a comment, suggestion, or correction
[For questions about usage, consult the Notes tab above or visit the JavaScript forum. Do not include more than two (2) lines of code in your comments. If you have suggestions or corrections, you can submit them to us.]

    
   
       
[optional]
 
[optional]

   

Comments feed Comment Feed RSS 2.0

7. From: qammar feroz
how to allow spaces in string regular exp.
04/09/2009 05:26:10

Hi!

it's great script and it save me a lot of time. thanks

to allow space,underscore and dash sign (_ and - )
I just replace the line of regular exp to

'special':/[^0-9a-zA-Z.\-_\s]+$/,

and it's still working fine :)

regards,
qammar
http://www.pkshops.com

5. From: matt
NICE script
11/20/2008 13:39:18

Great script!! How do I get it from limiting spaces? It works to good and won't allow spaces between words or numbers.

Matt

6. From: Lee (Admin)
12/02/2008 11:12:23

Not of the problem, Matt. It only blocks those items mentioned.

4. From: JLS
10/18/2008 14:20:14

Exellent prevent all SQL atacks injections.

3. From: Mukesh
Good job
06/03/2008 09:15:50

It is very useful.
Thanks

2. From: Farreina
09/13/2007 23:40:12

Nice code. Very useful. Thanks

1. From: Manojbabu
nice
08/18/2007 04:41:50

excellent job, i am tring this type code for last 2 weeks, my hats off to the author.


Do you write JavaScripts?
If you do, why not submit them to us?
We'll give you credit and a link back to your Web site.