JS Example: Control of illegal character input JS code

Source: Internet
Author: User

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 ">
&LT;TITLE&GT;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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.