Using the OnKeypress event, you can trap and prevent certain characters (repesented by ASCII decimal codes) from being entered in a form field. Just look up the ASCII code for any other characters you wish to block and add it to the script.
Add the below code to the <body> section of your page:
<scriptlanguage="javascript"type="text/javascript"> /* Visit http://www.yaldex.com/
for full source code
and get more free JavaScript, CSS and DHTML scripts! */ ie =(document.all)?1:0; n =!ie; Comment =false; Email =false; PostalCode =false;
function
Go(){ document.onkeypress=
keyDown; if(n){ document.captureEvents(Event.KEYPRESS);
}
}
function
keyDown(e){ var
keycode; if(window.event)
keycode =window.event.keyCode; elseif(e)
keycode =
e.which; elsereturntrue; if(Comment){
<formonSubmit="return
false;"> <b>This
field will not accept special characters: (like !@#$%^&* etc)<br></b> <textarearows=2cols=20name=commentsonKeyPress="Comment
= true; Email = false; PostalCode = false; Go();"></textarea> <br>
<br> This field will not accept double or
single quotes:<br> <inputtype=textname=txtEmailonKeypress="Comment
= false; Email = true; PostalCode = false; Go();"> <br>
<br> This field will only accept numbers:<br> <inputtype=textname=txtPostalCodeonKeypress="Comment
= false; Email = false; PostalCode = true; Go();">
</form>