Full version: jsB@nk » Form » Validation » Block Key Press
URL: https://www.javascriptbank.com/block-key-press.html
Tired 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
<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-->
<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-->