+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Member
    Join Date
    Jun 2001
    Location
    England
    Posts
    41

    HTML Tags removed from ASP/Javascript

    I was wondering if there was any built in function for ASP/Javascript that filtered out HTML Tags from any info entered by user (ie input text boxes etc)
    Or do i have to create my own.

  2. #2
    Senior Member golfcart's Avatar
    Join Date
    Jan 2000
    Location
    Michigan
    Posts
    748
    You can do it with ASP

    Code:
    '[ClearHTMLTags]
    	
    'Coded by Jóhann Haukur Gunnarsson
    'joi@innn.is
    	
    '  Purpose: This function clears all HTML tags from a
    '           string using Regular Expressions.
    '   Inputs: strHTML;
    '            A string to be cleared of HTML TAGS
    '	intWorkFlow;
    '            An integer that if equals to 0 runs only the RegExp filter
    '              .. 1 runs only the HTML source render filter
    '              .. 2 runs both the RegExp and the HTML source render
    '              .. >2 defaults to 0
    '  Returns: A string that has been filtered by the function
    	
    function ClearHTMLTags(strHTML, intWorkFlow)
      'Variables used in the function
    		
      dim regEx, strTagLess
    		
      '---------------------------------------
      strTagless = strHTML
      'Move the string into a private variable
      'within the function
      '---------------------------------------
    
      'regEx initialization
      '---------------------------------------
      set regEx = New RegExp 
      'Creates a regexp object		
      regEx.IgnoreCase = True
      'Don't give frat about case sensitivity
      regEx.Global = True
      'Global applicability
      '---------------------------------------
    
      'Phase I
      '	"bye bye html tags"
      if intWorkFlow <> 1 then
        '---------------------------------------
        regEx.Pattern = "<[^>]*>"
        'this pattern mathces any html tag
        strTagLess = regEx.Replace(strTagLess, "")
        'all html tags are stripped
        '---------------------------------------
      end if
    		
      'Phase II
      '	"bye bye rouge leftovers"
      '	"or, I want to render the source"
      '	"as html."
    
      '---------------------------------------
      'We *might* still have rouge < and > 
      'let's be positive that those that remain
      'are changed into html characters
      '---------------------------------------	
    
      if intWorkFlow > 0 and intWorkFlow < 3 then
        regEx.Pattern = "[<]"
        'matches a single <
        strTagLess = regEx.Replace(strTagLess, "<")
    
        regEx.Pattern = "[>]"
        'matches a single >
        strTagLess = regEx.Replace(strTagLess, ">")
        '---------------------------------------
      end if
    		
      'Clean up
      '---------------------------------------
      set regEx = nothing
      'Destroys the regExp object
      '---------------------------------------	
    		
      '---------------------------------------
      ClearHTMLTags = strTagLess
      'The results are passed back
      '---------------------------------------
    end function
    Next time post questions like this under Programming and Web Development. You will get a quicker response

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts







New Security Features Planned for Firefox 4
Another Laptop Theft Exposes 21K Patients' Data
Oracle Hits to Road to Pitch Data Center Plans
Microsoft Preps Array of Windows Patches
Microsoft Nears IE9 Beta With Final Preview
Simplified Analytics Improve CRM, BI Tools
Android Passes RIM as Top Mobile OS in 2Q
VMware Updates Hyperic System Management
File Monitoring Key to Enterprise Security
LinkedIn Snaps Up SaaS Player mSpoke