Remove ASCII 1 to 31 from input string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agoyal2
    New Member
    • Apr 2007
    • 5

    Remove ASCII 1 to 31 from input string

    Hi All,

    I have a simple ASP page with a text box and a submit button which displays the text box value on the page when it is submitted after removing all special characters. It works fine in normal cases but fails when the user types the key combination Alt+1 (☺) to Alt+31(▼). For ex: It converts Alt+1 to 9786. I am not sure what is the reason and how to fix this. Please help!

    The ASP code:
    Code:
    <html>
    <%
    Dim sData
    Dim ReplacedString
    
    sData = request("ASCIIData")
    
    Set RegularExpressionObject = New RegExp
    
    With RegularExpressionObject
    	.Pattern = "[^A-Za-z0-9]"
    	.IgnoreCase = True
    	.Global = True
    End With
    
    ReplacedString = RegularExpressionObject.Replace(sData, " ")
    
    Response.Write "Replaced " & sData & " with " & ReplacedString
    
    Set RegularExpressionObject = nothing
    
    %>
    
    <form id="f1" name="f1" method="post" action="ASCII.asp">
    	<input name="ASCIIData"/>
    	<input type="submit" value="submit"/>
    </FORM>
    </html>
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    Off hand I'm not familiar with the regular expression object

    but...why not just...

    Code:
    if cstr(ConvertedValue) = "9786" then
         ConvertedValue = DesiredValue
    end if

    Comment

    Working...