Jump to content

Recommended Posts

Posted

Hi

i have an edit that i only want to allow numbers and "-" to be entered, is there a way for me to do that?

i now that i can use $ES_NUMBER to set only numbers, but then how to also allow the "-", i have read the helpfile 3 time to finde a way and still in end up with nothing :)

Regards

/Rex

Posted

You'll have to monitor the text in the control with a loop, and actively react to invalid characters by changing the input (add an annoying Beep when wrong characters are input, to help train the user).

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Posted

You'll have to monitor the text in the control with a loop, and actively react to invalid characters by changing the input (add an annoying Beep when wrong characters are input, to help train the user).

:evil:

That's what i was thought, i think i just hit my colleges when they don't do it right ;).

Cheers

/Rex

Posted

If its an input box then perhaps you could check the input with some sort of StrRegExp pattern after the button has been hit, maybe in a while loop until the input meets your pattern parameters.

Cant help with a pattern sorry.

It an edit, but i could still do some StrRegExp, but i think that Brute violence would work better ;) that way i'm sure that the only do it ones.

Cheers

/Rex

Posted

This example is a modified version of the script from here.

It filters the input into an edit control.

It enables only numeric characters, a dot, a dash and @CRLF to be entered into an edit control.

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

; http://www.autoitscript.com/forum/index.php?showtopic=105638&view=findpost&p=746646
Global $inTest
Local $hGui

$hGui = GUICreate("Input Filter", 300, 130, -1, -1)

$inTest = GUICtrlCreateEdit("", 5, 5, 290, 120)

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GUISetState(@SW_SHOW)

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd


Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord
    Local $iCode = BitShift($wParam, 16) ;HiWord
    If $iIDFrom = $inTest And $iCode = $EN_CHANGE Then
        $Read_Input = GUICtrlRead($inTest)
        If StringRegExp($Read_Input, '[^0-9.\-\v]') = 1 Then _
                GUICtrlSetData($inTest, StringRegExpReplace($Read_Input, '([^0-9.\-\v])', ''))
    EndIf
EndFunc ;==>MY_WM_COMMAND

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
×
×
  • Create New...