Jump to content
Sign in to follow this  
darkjohn20

StringRegExp Help

Recommended Posts

darkjohn20

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
Ascend4nt

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
darkjohn20

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

Share this post


Link to post
Share on other sites
Mison

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.