Jump to content

Limit edit to only Numbers and - "dash"


Rex
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...