Home > Web Front-end > JS Tutorial > body text

js code that filters special characters input_javascript skills

WBOY
Release: 2016-05-16 18:21:37
Original
931 people have browsed it
Copy code The code is as follows:

<script> <br>function TextValidate() { <br> var code; <br>var character; <br>var err_msg = "The folder name cannot contain one of the following characters: n \ / : * ? " < > | & , "; <br>if (document.all ) <br>{ <br>code = window.event.keyCode; <br>} <br>else { <br>code = arguments.callee.caller.arguments[0].which; <br>} <br> var character = String.fromCharCode(code); <br>var txt = new RegExp("[\*,\&,\\,\/,\?,\|,\:,\<,\>, "]"); <br>if (txt.test(character)) { <br>alert(err_msg); <br>if (document.all) { <br>window.event.returnValue = false; <br> } <br>else { <br>arguments.callee.caller.arguments[0].preventDefault(); <br>} <br>} <br>} <br></script>

asp:TextBox ID="txtFolderNameEng" CssClass="frmTxt" runat="server" MaxLength="200" onkeypress="TextValidate()" >

Use the above in the onkeypress event of the textbox Just use the method.

You can limit the input of *,&,,/,?,|,<,>. If you need to limit more special symbols, just add var txt = new RegExp("[\*,\ &,\\,\/,\?,\|,\:,\<,\>,"]");
.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template