»
EnglishFrenchVietnamese

Print - Block Key Press - JavaScriptBank.com

Full version: jsB@nk » Form » Validation » Block Key Press
URL: https://www.javascriptbank.com/block-key-press.html

Block Key Press © JavaScriptBank.comTired of customers using characters that could possibly render your forms useless? This JavaScript prevents a user from entering certain special characters in designated form fields.

Full version: jsB@nk » Form » Validation » Block Key Press
URL: https://www.javascriptbank.com/block-key-press.html



JavaScript
<script language="javascript">/*Corneliu Lucian 'Kor' Rusucorneliulucian[at]gmail[dot]com*/var r={  'special':/[\W]/g,  'quotes':/['\''&'\"']/g,  'notnumbers':/[^\d]/g}function valid(o,w){  o.value = o.value.replace(r[w],'');}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<form id="myform" method="" onsubmit="return false;">  This field will not accept special characters: (like !@#$%* etc,) - but accepts underscore _  <br>  <input size="35" name="comments" onkeyup="valid(this,'special')" onblur="valid(this,'special')" type="text">  <br>  <br>  This field will not accept double or single quotes:  <br>  <input size="35" name="txtEmail" onkeyup="valid(this,'quotes')" onblur="valid(this,'quotes')" type="text">  <br>  <br>  This field will only accept integer numbers:  <br>  <input size="35" name="txtPostal" onkeyup="valid(this,'notnumbers')" onblur="valid(this,'notnumbers')" type="text"></form><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->