Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP Classic: Check if string only consists of valid chars

I've been checking all over the internet but really can't find any specific solution of my problem.

How do I check if a string consists of only the declared valid characters?

I want my string to consists of only 0-9, A-Z and a-z

So the string oifrmf9RWGEWRG3oi4m3ofm3mklwef-qæw should be invalid because of - and æ while the string joidsamfoiWRGWRGmoi34m3f should be valid.

I have been using the build-in RegExp to strip the strings, but is it possible to just make it check and return a boolean false or true?

my regexp:

set pw = new regexp
pw.global = true
pw.pattern = "[^a-zA-Z0-9]"

newstring = pw.replace("iownfiwefnoi3w4mtl3.-34ø'3", "")

Thanks :)

like image 848
MicBehrens Avatar asked Oct 25 '11 14:10

MicBehrens


2 Answers

You could do a Test which returns True or False

If( pw.Test("string") ) Then
'' Do something
End If
like image 72
Doozer Blake Avatar answered Oct 03 '22 10:10

Doozer Blake


Try -

Dim myRegExp, FoundMatch
Set myRegExp = New RegExp
myRegExp.Pattern = "[^a-zA-Z0-9]"
FoundMatch = myRegExp.Test("iownfiwefnoi3w4mtl3.-34ø'3")

If FoundMatch is true the RegEx engine has found a character that is not a-z or A-Z or 0-9 and your string is not valid.

like image 23
ipr101 Avatar answered Oct 03 '22 10:10

ipr101