Fadi Posted August 1, 2019 Share Posted August 1, 2019 hi, I'm trying to create an input but force the input to be in the form HH:MM:SS and validate that the input is in this format. Any idea? Thank you in advance Link to comment Share on other sites More sharing options...
Fadi Posted August 1, 2019 Author Share Posted August 1, 2019 Example $Input1 = GUICtrlCreateInput("", 19, 40, 213, 21) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 1, 2019 Moderators Share Posted August 1, 2019 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
water Posted August 1, 2019 Share Posted August 1, 2019 Search the forum for "input validation" and you will find a lot of UDFs to assist you. Example: My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Nine Posted August 1, 2019 Share Posted August 1, 2019 Or simply : If StringRegExp ($sTime, "^\d{2}:\d{2}:\d{2}$") Then $aTime = StringSplit ($sTime, ":", $STR_NOCOUNT) If $aTime[0] < 24 And $aTime[1] < 60 And $aTime[2] < 60 Then ... ; it is ok now EndIf Fadi 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Fadi Posted August 1, 2019 Author Share Posted August 1, 2019 Thank you Link to comment Share on other sites More sharing options...
mikell Posted August 1, 2019 Share Posted August 1, 2019 (edited) But don't forget to check that the result is not something like 85:86:87 ... Edit For the fun expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 200, 70) $Label = GUICtrlCreateLabel("Enter HH:MM:SS (24 h format)", 22, 8, 160, 17) $input = GUICtrlCreateInput("", 50, 30, 100, 24) GUICtrlSetLimit(-1, 8) GUICtrlSetFont(-1, 12) GUISetState() GUIRegisterMsg($WM_COMMAND, '_WM_COMMAND') GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") While 1 Sleep(10) WEnd Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $id = BitAND($wParam, 0x0000FFFF) Local $code = BitShift($wParam, 16) If $id = $input AND $code = $EN_UPDATE Then Local $content = GUICtrlRead($input) $n = StringLen($content) If ($n = 1 or $n = 2 or $n = 4 or $n = 5 or $n = 7 or $n = 8) _ and not StringIsDigit(StringRight($content, 1)) Then _ GUICtrlSetData($input, StringTrimRight($content, 1)) If ($n = 3 or $n = 6) and not (StringRight($content, 1) == ":") Then _ GUICtrlSetData($input, StringTrimRight($content, 1)) If $n = 2 and Number($content) > 23 Then GUICtrlSetData($input, "") If ($n = 5 or $n = 8) and Number(StringRight($content, 2)) > 59 Then _ GUICtrlSetData($input, StringTrimRight($content, 2)) EndIf Return $GUI_RUNDEFMSG EndFunc Func _Exit() Exit EndFunc Edited August 1, 2019 by mikell Link to comment Share on other sites More sharing options...
BrewManNH Posted August 2, 2019 Share Posted August 2, 2019 I'd use 3 (or 4) input controls, an updown control on each, and set the limit for the controls. Use the parameter $ES_NUMBER so that only numbers can be used. Easy and done. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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