Sign in to follow this  
Followers 0
darkjohn20

StringRegExp Help

4 posts in this topic

I'm trying to figure out a way to validate usernames. The StringRegExp needs to find any of the following in any order, in any place, and in any quantity. It doesn't need to return them, just check if it exists.

` ~ @ # $ % ^ & * ( ) { } [ ] ; : ' " / \ > < . ,

I have this so far, but it doesn't work for some reason. I'm guessing it's probably because of the quotes inside the quotes.

"[`~@#$%^&\*\(\)\{\}\[\];:'"\/\\><.,]"

I read the page on having double quotes like "here is a ""double-quote"" - ok?" but I don't know if it can help me. I tried that, as well, with no success.

Share this post


Link to post
Share on other sites



This seems to work for me. I added \Q..\E since there was so many escapes it was just begging for it. Note where I doubled the "". Hope it helps

$sStr="whatever you want here"
$bRes=StringRegExp($sStr,"[\Q`~@#$%^&*(){}[];:'""/\><.,\E]")
ConsoleWrite("Result:"&$bRes&@CRLF)

Share this post


Link to post
Share on other sites

Thanks, works great. I've got to remember \Q and \E. ;)

Share this post


Link to post
Share on other sites

Alternatively, you can use StringSplit to check if the string contains any of the delimiters specified.

;~ $string = "clean string"
$string = '"here is a ""double-quote"" - ok?" '
$delimiter = "`~@#$%^&*(){}[];:'/\><.,"&'"'
StringSplit($string,$delimiter) ; If no delimiters were found @error is set to 1
If @error Then 
    MsgBox(0,"","They don't exist!")
Else
    MsgBox(0,"","They do exist!")
EndIf

Hi ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0