The HTML file code is as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<TITLE>JS controls the input of illegal characters </title>
<body>
<form>
<p> here is not allowed to enter the following characters: (such as!@#$%^&*) <br>
<textarea rows= "2" cols= "Name=" "Comments" onkeypress= "checkcomments" () ></textarea>
</p>
<p> not allowed to enter quotes here:<br>
<input type= "text" name= "Txtemail" onkeypress= "Checkemail ()"/>
</p>
<p> only digital:<br> can be entered here
<input type= "text" name= "Txtpostalcode" onkeypress= "Checkpostalcode ()"/>
</p>
<p> only uppercase English:<br> can be entered here
<input type= "text" name= "Txtenglish" onkeypress= "checkenglish ()"/>
</p>
</form>
</body>
JS file code is as follows:
<script type= "Text/javascript" language= "JavaScript" >
/*
* The range of special characters represented in ASCII code is 32~48,57~65,90~97
* EVENT.RETURNVALUE=FALSE; set keyboard input Master False, you cannot enter content in a text box
*/
function checkcomments () {
if ((Event.keycode > && Event.keycode < 48)
(Event.keycode > && Event.keycode < 65)
(Event.keycode > && event.keycode < 97)
) {
Event.returnvalue = false;
}
}
/*
* The ASCII code for the quotes is 34 and 39.
*/
function Checkemail () {
if (Event.keycode = = Event.keycode = = 39) {
Event.returnvalue = false;
}
}
/*
* The ASCII representation range for the number is 45~57
*/
function Checkpostalcode () {
if (Event.keycode < Event.keycode >57) {
Event.returnvalue = false;
}
}
/*
* Uppercase English letter ASCII representation range is 65~91
* Lowercase English Letter ASCII representation range is 97~123
*/
function Checkenglish () {
if (Event.keycode < Event.keycode > 91) {
Event.returnvalue = false;
}
}
</script>