Jump to content

Letters in "Input"


Recommended Posts

Hi all,

How do I allow an input control (GUICtrlCreateInput) to get only digits and dots?

$ES_NUMBER - allows only digits, but I need to be able to type something like this only:   2.15.1598.1

Can you help me please? 

Link to comment
Share on other sites

use the on change event to assess the text field of the inputbox

if it's always the same number of dots and sets of digits you could have four input boxes, one for each number and append them together at the end separated by dots.  Use the $ES_NUMBER control style to restrict input to numbers only.

Edited by gruntydatsun
corrected error
Link to comment
Share on other sites

Try this.

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


$hGui = GUICreate("My GUI edit")

$IP = GUICtrlCreateInput("", 10, 15, 200, 22)
$IP2 = GUICtrlCreateInput("", 10, 40, 80, 22)

GUICtrlCreateLabel("<- Digits and dots only.", 215, 15, 200, 22)
GUICtrlSetFont(-1, 12)
GUICtrlCreateLabel('<-  "n.nn.nnnn.n" pattern only.', 95, 40, 300, 22)
GUICtrlSetFont(-1, 12)


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $IP Then ; Only digits and dots
        If $nNotifyCode = $EN_CHANGE Then
            GUICtrlSetData($IP, StringRegExpReplace(GUICtrlRead($IP), "[^0-9.]+", ""))
    If $nID = $IP2 Then ; Allow n.nn.nnnn.n characters only - where n is a digit. For example 2.15.1598.1 is allowed.
        If $nNotifyCode = $EN_CHANGE Then
            $temp2 = GUICtrlRead($IP2)
            $REPattern = "\d\.\d\d\.\d\d\d\d\.\d"
            $iLen = StringLen($temp2)
            If StringRegExp($temp2, StringLeft($REPattern, $iLen * 2)) = 0 Or $iLen > 11 Then GUICtrlSetData($IP2, StringTrimRight($temp2, 1))
EndFunc   ;==>WM_COMMAND


Link to comment
Share on other sites

  • 5 months later...

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...