darkjohn20 Posted September 29, 2010 Posted September 29, 2010 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.
Ascend4nt Posted September 29, 2010 Posted September 29, 2010 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) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
darkjohn20 Posted September 30, 2010 Author Posted September 30, 2010 Thanks, works great. I've got to remember \Q and \E.
Mison Posted September 30, 2010 Posted September 30, 2010 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 ;)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now