The function of text box filtering written by ASP

Source: Internet
Author: User
Tags gettext reset
function | text box

A good and useful function! I hope it works for you.

<%
Function Requesttext (Textstring,texttype,textname,textnumbermost,textnumberleast)
' TextString gets the value in the text box
' Texttype set the type of text box name, such as input for 0,textarea 1
' Textname the name displayed when the error is encountered
' Textnumbermost text box can fill in the maximum number of bytes
' Textnumberleast text box can fill in the minimum number of bytes
Gettext=request (TextString)
Select Case Texttype
Case 0
Gettext=replace (GetText, "<", "<")
Gettext=replace (GetText, ">", ">")
Gettext=replace (GetText, "'", "" ")
If Len (GetText) >textnumbermost Then
Response.Write ("<script>alert" you enter a byte in the &TextName& entry exceeds the maximum byte "&TextNumberMost&", please return to re-enter! ""); History.go ( -1) </script> ")
Response.End
Elseif Len (GetText) <textnumberleast Then
Response.Write ("<script>alert" you enter a byte less than the minimum byte "&TextNumberLeast&" in the "&TextName&" entry, please return to re-enter! ""); History.go ( -1) </script> ")
Response.End
End If
Case 1
Gettext=replace (GetText, "<", "<")
Gettext=replace (GetText, ">", ">")
Gettext=replace (GetText, "'", "" ")
Gettext=replace (GetText, "", "")
Gettext=replace (Gettext,vbcrlf, "<br/>")
If Len (GetText) >textnumbermost Then
Response.Write ("<script>alert" you enter a byte in the &TextName& entry exceeds the maximum byte "&TextNumberMost&", please return to re-enter! ""); History.go ( -1) </script> ")
Response.End
Elseif Len (GetText) <textnumberleast Then
Response.Write ("<script>alert" you enter a byte less than the minimum byte "&TextNumberLeast&" in the "&TextName&" entry, please return to re-enter! ""); History.go ( -1) </script> ")
Response.End
End If
End Select
Requesttext=gettext
End Function
%>
<%
' Example
If Request ("post") <> "then
Name=requesttext ("name", 0, "name", 10,2)
Text=requesttext ("text", 0, "content", 255,0)
Response.Write "Name value is:" &Name& "<br> content value is:" &text
End If
%>

<form method= "Get" >
<p> name <input type= "text" name= "name" size= "></p>
<p> content <textarea rows= "6" name= "text" cols= "></textarea><input type=" Submit "value=" submitted "Name=" Post ">
<input type= "reset" value= "reset" name= "B2" ></p>
</form>



Related Article

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.