KaFu Posted May 12, 2009 Share Posted May 12, 2009 (edited) HiHo Community,I want to create an Input Control which allows only positive 5 digit numbers with max. 2 digit decimal as input. $ES_NUMBER does not allow digits, so i thought I'll define a wm_notify or loop using StringRegExpReplace(), but I could not figure out the correct pattern. Maybe someone with deeper RegEx knowledge could help me out?Valid:99999.99 (only 1 dot allowed)1.110.1 (forcing a 0 in front if . is entered first possible? Possible for sure , whats the pattern?)Invalid:Non-Numeric and not dot-1using something likeguictrlsetdata($input,StringRegExpReplace(guictrlread($input),"???","$1.$2"))Best RegardsEdit: The "forcing 0 in front" part is in fact quiet easy, after StringRegExpReplace() I'll just append anif stringleft(guictrlread($input,1),1) = "." then guictrlsetdata($input,0 & guictrlread($input)) , so skip that.Edit 2: Appended (not working correct yet) test code.So literally the expression would be something like (1-5 digits AND/OR 1 dot AND 0-2 digits).#include<GUIConstantsEx.au3> GUICreate("Test") $input = GUICtrlCreateInput("", 10, 10, 100) $input_save = "" GUISetState() Do Sleep(10) $input_read = GUICtrlRead($input) if $input_save <> $input_read Then $input_read = StringRegExpReplace($input_read,"[^\d]","$1") if stringleft($input_read,1) = "." then $input_read = 0 & $input_read GUICtrlSetData($input, $input_read) $input_save = $input_read endif Until GUIGetMsg() = $GUI_EVENT_CLOSE Edited May 13, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
oMBRa Posted May 12, 2009 Share Posted May 12, 2009 how should we replace a number with more than 5 digit like 99999999.99, or a negative one? Link to comment Share on other sites More sharing options...
KaFu Posted May 12, 2009 Author Share Posted May 12, 2009 (edited) 99999.99 is max (delete/ignore 6th digit) and negative values should not be allowed. Edited May 12, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 12, 2009 Moderators Share Posted May 12, 2009 (edited) $input_read = StringRegExpReplace($input_read,"^(\D*)(\d{0,5})(\d+)?(\.)?(\d{0,2})?(.*?)\z","\2\4\5") Edit: Interesting enough, I had to change that up a bit:$input_read = StringRegExpReplace($input_read,"^(\D*)(\d(?:\d?\d?\d?\d?))(\d+)?(\.)?(\d{0,2})?(.*?)\z","\2\4\5") Edited May 12, 2009 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 12, 2009 Share Posted May 12, 2009 Check the UDF RestrictControlRegExp, and use it as following:#include <GUIConstantsEx.au3> #include <RestrictControlRegExp.au3> ; _RegEx_RestrictControl_Setup() GUICreate("Test") $input = GUICtrlCreateInput("", 10, 10, 100) _RegEx_RestrictControl_Add($input, "^[0-9]{1,5}\.[0-9]{0,2}$", "99999.99") $input_save = "" GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndIt's almost what you need, except the behaviour on entered dot at the begining. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
KaFu Posted May 12, 2009 Author Share Posted May 12, 2009 Interesting enough, I had to change that up a bit Perfect , seems to fit my needs. Thanks a lot! #include<GUIConstantsEx.au3> GUICreate("Test") $input = GUICtrlCreateInput("", 10, 10, 100) $input_save = "" GUISetState() Do $input_read = GUICtrlRead($input) if $input_save <> $input_read Then if stringleft($input_read,1) = "." then $input_read = 0 & $input_read $input_read = StringRegExpReplace($input_read,"^(\D*)(\d(?:\d?\d?\d?\d?))(\d+)?(\.)?(\d{0,2})?(.*?)\z","\2\4\5") GUICtrlSetData($input, $input_read) $input_save = $input_read endif Until GUIGetMsg() = $GUI_EVENT_CLOSE in a wm_notify if the input looses focus. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
KaFu Posted May 12, 2009 Author Share Posted May 12, 2009 It's almost what you need, except the behaviour on entered dot at the begining.What should be solved with anif stringleft($input_read,1) = "." then $input_read = 0 & $input_readsomewhere within that function too, will definitely check it out. Thanks to you too ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 12, 2009 Share Posted May 12, 2009 $input_read = StringRegExpReplace($input_read,"^(\D*)(\d{0,5})(\d+)?(\.)?(\d{0,2})?(.*?)\z","\2\4\5") Edit: Interesting enough, I had to change that up a bit:$input_read = StringRegExpReplace($input_read,"^(\D*)(\d(?:\d?\d?\d?\d?))(\d+)?(\.)?(\d{0,2})?(.*?)\z","\2\4\5")You keeping amaze me with those RegExp patterns every time, you are the best in it! Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
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