ASP Classic: check to see if the string contains only valid characters

I checked everything over the Internet, but I really can’t find any specific solution to my problem.

How to check if a string consists only of declared valid characters?

I want my string to consist only of 0-9, AZ and az

Therefore, the line oifrmf9RWGEWRG3oi4m3ofm3mklwef-qæw must be invalid due to - and æ while the line joidsamfoiWRGWRGmoi34m3f must be valid.

I use the built-in RegExp to split the lines, but is it possible to just check and return the boolean value 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:)

+7
source share
5 answers

You can do a Test that returns True or False

 If( pw.Test("string") ) Then '' Do something End If 
+7
source

Try it -

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

If FoundMatch true, then the RegEx engine has detected a character that is not az or AZ or 0-9, and your string is invalid.

+2
source

You can do something like:

 Set match = pw.execute("iownfiwefnoi3w4mtl3.-34ø'3") if match.count > 0 then ' your pattern matched, so it invalid badString = true else badString = false end if 
0
source

Instead of replacing, you can look and see if there is a match for any character outside the white list. Common to each match syntax here

0
source

[a-zA-Z0-9] works ... I tried it against your line here http://gskinner.com/RegExr/?2u7c3 and here http://regexpal.com/ ... pull out the carrots. I also can’t remember that the regex vexcript engine is used, but this may have something to do with your problem. It also works ...

\ D? \ W

0
source

All Articles