The inputbox can't guess the precise moment when the typing is assumed to be complete
The previous script is intended to check the typing while it is entered. The final comparison/check must be done when the input content is read, and the easiest way to do this is to check if the input contains at least one digit
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
GUICreate("Input Filter", 300, 60, -1, -1)
Global $inTest = GUICtrlCreateInput("", 5, 5, 290)
$btn = GUICtrlCreateButton("Validate", 200, 30, 60, 25)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then Exit
If $msg = $btn Then
$content = GuiCtrlRead($inTest)
If StringRegExp($content, '\d') Then
Msgbox(0,"", "OK, " & $content & " is valid")
Else
GUICtrlSetData($inTest, "")
Msgbox(0,"", "Entry is invalid. Try again")
EndIf
EndIf
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 not StringRegExp($Read_Input, '^[\d-]?\d*(?:\.\d*)?$') Then
GUICtrlSetData($inTest, StringTrimRight($Read_Input, 1))
Else
GUICtrlSetData($inTest, StringRegExpReplace($Read_Input, '^(-?)\.', '${1}0.'))
EndIf
EndIf
EndFunc;==>_WM_COMMAND
Edit
Rectification : it could be done though by checking $EN_KILLFOCUS with WM_COMMAND (moment when the input loses focus) but it is hazardous, such a behavior could be baffling for the user ^^