Sign in to follow this  
Followers 0
tweakster2010

StringRegExp in GuiCtrlRead

20 posts in this topic

Hey Guys,

 

I have been experimenting with StringRegExp to try and make a program i am making restrict the passwords to match certain criteria. Now When I do a generic check i can get 1 and 0 no problem. My understanding is 1 on a return means it matches the criteria and 0 means its missing... or did I do that wrong?

Either way My experiment was started by this to confirm a simple adjustment gave me different results.

Local $Numbers123 = StringRegExp("numberS1",'[a-z][A-Z][0-9]')
MsgBox(0,"",$Numbers123)

I remove the 1 and put the 1 back to change from returning a 1 or 0. So i Applied this to a basic UI just to test it and I always return a 0. 

GuiCreate("",200,200)
$input = GUICtrlCreateInput("",10,10,50)
$button = GuiCtrlCreateButton("Click Me",10,50)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
Case $button
Local $Numbers123 = StringRegExp(GuiCtrlRead($input),'[a-z][A-Z][0-9]')
MsgBox(0,"",$Numbers123)
    EndSwitch
    WEnd

Whether the text I type in is Abc1 or abc or abc1 or 1 etc etc. Realistically my goal is make sure Abc1 is the more accepted confirmation. Any help would be greatly appreciated.

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

What you have now is a single lowercase char a-z, a single uppercase char A-Z and a number zero to nine. I think you meant ^[a-zA-Z0-9]$? Am I right?

Also in my signature I have a wonderful password validator.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

I believe you are right good sir, i was reading that. I was more concerned that I was able to get the tests to come up properly but not the rest of the formula, the main program i included a stringLen aspect to make sure the length is on par.

 

I guess the main issue is it works without hitting the UI and its a very generic UI example I threw together as the main program right now has a lot of company related stuff I would have to remove out :/ But even my generic wont return a value other than 0 in the UI vs getting 1 or 0 based on if I remove a single aspect from the previous line. Hope that made sense my head has turned mush reading stringregexp all day and the wiki as well as searching the forums for a close example of what I am going for. :)

Share this post


Link to post
Share on other sites

I have no clue I'm afraid as to what you're talking about. Did you check my UDF I mentioned?


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Yes I was taking a gander at it :)

I have the right If Then mentality on it though for a simple 1-2 lines of script. The tool I created and am just fine lining is a password manager where there is 9 different passwords for 9 different domains our administrator ID's have access to. So the end goal is 

GuiCreate("",200,200)
$input = GUICtrlCreateInput("",10,10,50)
$button = GuiCtrlCreateButton("Click Me",10,50)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
Case $button
Local $Numbers123 = StringRegExp(GuiCtrlRead($input),'[a-z][A-Z][0-9]')
MsgBox(0,"",$Numbers123)
    EndSwitch
    WEnd

Is this to work where it will return a 1, currently it only returns 0. Even if what is typed into the GUI is Ab1 (basically matching the minimalistic answer but anything you type in doesnt change the results of a 0. That is where I am getting my confusion, maybe its a bug between StringRegExp and the ability to GuiCtrlRead?

 

Thanks though I will take a gander further into the UDF, it looks scary as regular expressions is still VERY new for me >.> :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Local $Numbers123 = StringRegExp(GuiCtrlRead($input),'[a-z]|[A-Z]|[0-9]')

This is closer to right but it accepted anything :(

Edited by tweakster2010

Share this post


Link to post
Share on other sites

JG, my adjustment returns 1, whereas yours 0, for the OPs original requirement, but I dont know why.  Can you enlighten please.

msgbox(0,'', StringRegExp("Abc1",'[^a-zA-Z0-9]'))    ;Fails

msgbox(0,'', StringRegExp("Abc1",'[^a-z][^A-Z][^0-9]')) ;passes

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

His carrot was on the outside and i missed that!.

 

With the Carrot on the inside it fails some of the simple ones like aB1.

When I do this

Local $Numbers123 = StringRegExp(GuiCtrlRead($input),'[^a-z][^A-Z][^0-9]')

They work unless i do aB1 but if I do Ba1 or 1Ba or 1aB those work. Just not in the right order. I remember when  I was reading it today that the carrot meant it would be at the start but I do not know why [a-zA-Z0-9] doesnt appear to like any simple comparisons though >.>

Local $Numbers123 = StringRegExp(GuiCtrlRead($input),'^[a-zA-Z0-9]')

This accepts any thing not just all 3 requirements.

 

Share this post


Link to post
Share on other sites

Also, you can prevent user to use bad characters :

#Include <WindowsConstants.au3>
#Include <GUIConstantsEx.au3>
#Include <EditConstants.au3>

GUICreate("GUI")

$input = GUICtrlCreateInput("", 10, 10, 100, 25)
; $input = GUICtrlCreateInput("", 10, 10, 100, 25, $ES_PASSWORD)

GUISetState()

GUIRegisterMsg ($WM_COMMAND, "_WM_COMMAND") 

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd


Func _WM_COMMAND($hWnd, $imsg, $iwParam)
    Local $nNotifyCode = BitShift($iwParam, 16)
    Local $nID = BitAND($iwParam, 0x0000FFFF)
    Local $sText, $sNewText
   
    If $nNotifyCode = $EN_CHANGE AND $nID = $input Then
        $sText = GUICtrlRead($input)
        $sNewText = StringRegExpReplace($sText, "[^a-zA-Z0-9]", "")
        If @extended Then GUICtrlSetData($input, $sNewText)
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

 

Share this post


Link to post
Share on other sites

no worries, it seems everybody spoke at once.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

@jguinch your edit still shows as a fails for just Ab1 which again would fall to the acceptable range. I have in the main program stringLen already working so im just making sure the other main requirements are hit, some require No specials some specials and no numbers so the concept of getting this to work this way is it will cut out extra for me in the future. :)

 

Basically I need these all should pass: Ab1, A1b, bA1, b1A, 1bA, ,1Ab  :)

Edited by tweakster2010
corrected my horrible explanation.

Share this post


Link to post
Share on other sites

Still working on this today, I was trying to use your UDF @Guinness but I guess the issue I am running into is associating it correctly. I was trying to use it as an include then utilize _PasswordValid_Ints as well as a few others but it was not allowing me. If i took the example and adjusted it with the full value ahead of time and not reading the input I have setup currently it appears it would work. Its Definitely amazing work I just unfortunately am failing to understand how to incorporate it :( Just like RegExp itself is a tough area for me I want to get down. DLL structure in itself stomps me right now my focus has been on GUI  / AD / Independent scripts or functions to improve my work flow. :)

 

I dont doubt your UDF works just that I am not implementing it correctly :(

 

I did some further searching and found a javascript with the expression how I was looking for it.

 

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$

I only have to modify the {8,} for length of other choices :)

Share this post


Link to post
Share on other sites

Lets say your comments are not very clear  :D
Maybe this ? (replace the + by {n} to force a n characters length)

GuiCreate("",200,200)
$input = GUICtrlCreateInput("",10,10,50)
$button = GuiCtrlCreateButton("Click Me",10,50)
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
      Case $button
           Local $Numbers123 = StringRegExp(GuiCtrlRead($input),'^[[:alnum:]]+$')
           MsgBox(0,"",$Numbers123)
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites

@mikell that works and is much shorter too!

 

I guess  when I was reading the :alnum: i was realizing I needed to bracket twice >.>? Tons of good info on this thread though from everyone :)

 

My comments can tend to get skewed when I get into a lot of different thoughts to resolve the issue.

Share this post


Link to post
Share on other sites

I understand this trouble 
Welcome to the wonderful world of RegEx  :)

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

I would have helped you with my UDF if you had showed me what you tried. Honestly it's better to show than explain, because explanations aren't all that clear than code.

Edited by guinness
1 person likes this

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Ya I think the problem I ran into Guinness is I just tried to use it as an include. So no matter what happened I got extra message thrown telling me valid vs invalid. I ended up deleting the code out as I realized no offense at all meant, i couldnt understand it so if it did get to working i would still be lost. Better to try and go from what might help a little better for me.

 

I am sure sooner or later I will get to fully understanding a lot of the UDF's outside of me just using the Include followed by certain functions.

Share this post


Link to post
Share on other sites

Oh well. I tried to help, but I am not going to start guessing what you did or didn't do. It'd as simple as include the UDF, delete the example and voila. I updated it in the mean time.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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