Jump to content

Search the Community

Showing results for tags 'input validation'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. So a few times I have wanted/needed some sort of input validation (aka input mask) we had an old udf somebody made that sort of worked but was hard to use and a bit limited. As I started to learn regex of late sort of by chance I realized it could be used as a pretty great input validation. But it was a lot of code if you wanted to do it for multiple fields. So wrapped it up into a little function and sharing. Far from a UDF so putting in the example section, and I am not sure if what I am doing is even "good code" but it works for me and hope it is usefull for somebody. Basic RegEx knowledge will help you make the most of this, but a few examples are included below in the code snippet. #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Test GUI", 618, 276, 192, 124) $Label1 = GUICtrlCreateLabel("Test GUI", 168, 24, 47, 17) $Button1 = GUICtrlCreateButton("Toggle Validation", 290, 24, 110, 40) $Input1 = GUICtrlCreateInput("Max 10 Characters", 40, 72, 553, 21) $Input2 = GUICtrlCreateInput("Numb3rs 0nly", 40, 97, 553, 21) $Edit1 = GUICtrlCreateEdit("Max 10 Chars Numbers Only + Auto Line Break", 40, 120, 553, 105) GUISetState(@SW_SHOW) $iToggle = 1 While 1 Sleep(10) If Mod($iToggle, 2) = 0 Then ;Example 1 Limit to 10 Characters _GUIRegExValidate($Input1, "(.{10})(.)", "$1") ;Example 2 Can only type numbers _GUIRegExValidate($Input2, "[^\d]", "") ;Example 3 Combind More Than One On Same Input limit to 10 characters, limit to numbers only, line break @ 10 characters to new line _GUIRegExValidate($Edit1, "(.{10})(.)", "$1" & @CRLF) _GUIRegExValidate($Edit1, "[^\d\r\n]", "") EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $iToggle = $iToggle + 1 EndSwitch WEnd Func _GUIRegExValidate($sInputLabel, $sRegExCapture, $sRegExReplace) $Step1Read = GUICtrlRead($sInputLabel) $Step2Validate = StringRegExpReplace($Step1Read, $sRegExCapture, $sRegExReplace) If @Extended = 0 Then Return GUICtrlSetData($sInputLabel, $Step2Validate) EndFunc Or per recommendation you can use it with the GuiRegisterMsg so that you can only process the RegEx when you make a chance instead of in a constant loop. #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Test GUI", 618, 276, 192, 124) $Label1 = GUICtrlCreateLabel("Test GUI", 168, 24, 47, 17) $Button1 = GUICtrlCreateButton("Toggle Validation", 290, 24, 110, 40) $Input1 = GUICtrlCreateInput("Max 10 Characters", 40, 72, 553, 21) $Input2 = GUICtrlCreateInput("Numb3rs 0nly", 40, 97, 553, 21) $Edit1 = GUICtrlCreateEdit("Max 10 Chars Numbers Only + Auto Line Break", 40, 120, 553, 105) GUISetState(@SW_SHOW) $iToggle = 1 GUIRegisterMsg($WM_COMMAND, '_WM_COMMAND') While 1 Sleep(10) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $iToggle = $iToggle + 1 EndSwitch WEnd Func _GUIRegExValidate($sInputLabel, $sRegExCapture, $sRegExReplace) $Step1Read = GUICtrlRead($sInputLabel) $Step2Validate = StringRegExpReplace($Step1Read, $sRegExCapture, $sRegExReplace) If @Extended = 0 Then Return GUICtrlSetData($sInputLabel, $Step2Validate) EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If Mod($iToggle, 2) = 0 Then ;Example 1 Limit to 10 Characters _GUIRegExValidate($Input1, "(.{10})(.)", "$1") ;Example 2 Can only type numbers _GUIRegExValidate($Input2, "[^\d]", "") ;Example 3 Combind More Than One On Same Input limit to 10 characters, limit to numbers only, line break @ 10 characters to new line _GUIRegExValidate($Edit1, "(.{10})(.)", "$1" & @CRLF) _GUIRegExValidate($Edit1, "[^\d\r\n]", "") EndIf EndFunc
×
×
  • Create New...