View Full Version : making sure a string is numbers and letters only
How would I check a string to make sure that is only letters and number. So, there can't be /=+\-)( etc in it.
whammy
10-06-2002, 04:17 AM
Function OnlyWordChars(str) ''''''''''''''''''''
If IsNull(str) Then str = ""
Dim owcRegEx
Set owcRegEx = New RegExp
owcRegEx.Pattern = "\w"
owcRegEx.Global = True
OnlyWordChars = owcRegEx.Test(str)
End Function ''''''''''''''''''''''''''''''''''''
Will test for only word characters in a string (A-Z, a-z, 0-9, and _ (underscore)).
The function will return a boolean value (True or False).
You can use it as follows:
<%
myword = "blah+"
If OnlyWordChars(myword) = False Then
Response.Write("""myword"" contains invalid word characters!")
End If
%>
Just out of curiousity, what exactly would you like to use this for? This method may not be the best depending on your circumstances. :)
I am going to use this for making sure when somone tries to sign up using a username they do not enter in somehting like:
$money$man or \/\/icked
further more if you do respond to this. Where did you learn ASP?
whammy
10-06-2002, 05:16 AM
Well, I learned ASP from "Beginning ASP 3.0" (a textbook by Wrox.com) - and also through a lot of trial and error and experience working for a web development company that pretty much exclusively uses ASP. :)
I actually learned regular expressions from javascript however - although they can be used with very slight modifications for almost any language.
And if that's what you're going to use it for, it should work fine (I haven't tested it, but it's fairly straightforward).
:D
I guess that is the best way to learn. Thanks. :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.