Copy codeThe Code is as follows:
<Script>
Function TextValidate (){
Var code;
Var character;
Var err_msg = "the folder name suffix cannot contain one of the following characters: \ n \\/:*? \ "<> | &,";
If (document. all)
{
Code = window. event. keyCode;
}
Else {
Code = arguments. callee. caller. arguments [0]. which;
}
Var character = String. fromCharCode (code );
Var txt = new RegExp ("[\\*,\\&,\\\\,\\/,\\?, \\|, \\:,\<, \\>, \ "]");
If (txt. test (character )){
Alert (err_msg );
If (document. all ){
Window. event. returnValue = false;
}
Else {
Arguments. callee. caller. arguments [0]. preventDefault ();
}
}
}
</Script>
Asp: TextBox ID = "txtFolderNameEng" CssClass = "frmTxt" runat = "server" MaxLength = "200" onkeypress = "TextValidate ()">
Use the above method in the onkeypress event of textbox.
You can restrict the input *,&,\,/,?, |, <,>. To limit more special characters, you only need to specify the values in var txt = new RegExp ("[\\*,\\&,\\\\, \\/,\\?, \\|, \\:,\<, \\>, \ "]");
.