Block Key Press | JavaScriptSource

Block Key Press

Corneliu Rusu Aug 17, 2007

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


Leave a Response

(7 comments)

Hi![br /][br /]it's great script and it save me a lot of time. thanks[br /][br /]to allow space,underscore and dash sign (_ and - )[br /]I just replace the line of regular exp to[br /][br /]'special':/[^0-9a-zA-Z.\-_\s]+$/,[br /][br /]and it's still working fine :)[br /][br /]regards,[br /]qammar[br /]http://www.pkshops.com

qammar feroz Apr 9, 2009

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

Lee Dec 2, 2008

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

matt Nov 20, 2008

Exellent prevent all SQL atacks injections.

JLS Oct 18, 2008

It is very useful.[br /]Thanks

Mukesh Jun 3, 2008