WelcomeServicesPortfolioKnowledge BaseContact Us
27 Seconds, Inc.


Knowledge base View Article

need hosting?

Need hosting? We use and love our host - CrystalTech.com!
Need hosting? We use and love our host - CrystalTech.com!

Text Disguise - CAPTCHA-image/Human Interactive Proof web services

National Holiday Dates and Bank Holiday Dates - web site that provides the dates of national and bank holidays for the United States, United Kingdom, Ireland and Scotland

Holiday Web Service - web services for programmers to provide the dates of national and bank holidays in their applications for the United States, United Kingdom, Ireland and Scotland

Our Family Heart - web site to help families communicate no matter where they are

What?! You haven't heard about the greatest remote controlled flyer to come out in years?! Checkout the FlyTech DragonFly now!

Limit string to just specific characters.

Summary: There are many reasons to limit a string to just specific characters. Here's one way of doing that.
 
Keywords: ALPHA
ASP
CHAR
CHARACTERS
LOGIN
NUMERIC
VB
Applicable Software: Active Server Pages (ASP)
Visual Basic 6
 
Body:

For login names, it's generally a good idea to only allow particular characters. Namely, alphanumeric characters, underscore (_), hyphens (-) and periods (.).

Anything else and you'll never know what people will enter.

Function Validated(psString) 

Dim sReturn, iCounter, sChar
Dim sValid
	sValid = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-."
	For iCounter = 1 To Len(psString)
		sChar = Mid(psString, iCounter, 1)
		If InStr(1, sValid, sChar) > 0 Then
			sReturn = sReturn & sChar
		End If
	Next

	Validated = sReturn

End Function

To use it, you would do:

Dim sLogin, sLoginFixed
	sLogin = "Doug's 1 Test"
	sLoginFixed = Validated(sLogin)

	Response.Write sLoginFixed
	'Will return: Dougs1Test

 
Author: Craig Hawker
Posted On: 1/3/2003 5:50:59 AM

Rate this article: Average: 2.8
n/a12345678910
Comments?

Article Search   |   All Articles

 

 
©2002 27 Seconds, Inc. All Rights Reserved.