Sign in to follow this  
Followers 0
thezeus

Input Box - only digits and dots allowed

3 posts in this topic

Hi All,

I want to only allow dots and digits (for entering an ip-address) in a input box.

Any hints to solve it?

//Rolf

Share this post


Link to post
Share on other sites



I want to only allow dots and digits (for entering an ip-address) in a input box.

Not sure if this gets what you want - but it will inform you if the entry is not a valid IP (i.e. require 4 octets of numbers ranging from 0-255). Perhaps it'll give you some ideas.

#include <GUIConstants.au3>

$Form1 = GUICreate("AForm1", 300, 200, 193, 115)
$Button1 = GUICtrlCreateButton("Exit", 100, 80, 75, 25, 0)
$input1 = GUICtrlCreateInput("000.000.000.000", 100, 120, 90, 15)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE, $Button1
            Exit
        
        Case $input1 ; do this when the input field changes
            $IPOctets = StringSplit(GUICtrlRead($input1), ".") ; split the input field using the "." character

            If $IPOctets[0] <> 4 Then  ; test for number of octets
                MsgBox(0, "Entries insufficient", "Please enter four octets")
                ContinueLoop
            EndIf
            For $i = 1 To 4 ; check all four octets
                ;MsgBox(0, "Index & Value", $i & " & " & $IPOctets[$i])

                If StringIsDigit($IPOctets[$i]) = 0 Then ; test that entries are digits
                    MsgBox(0, "NAN", "Position " & $i & " is not a number.")
                    ContinueLoop(2)
                EndIf
                
                If $IPOctets[$i] <0 Or $IPOctets[$i] > 255 Then ; test that digits are within valid range
                    MsgBox(0, "Out of bounds", "Enter a number from 0 to 255 in position " & $i)
                    ContinueLoop(2)
                EndIf
                
            Next
            MsgBox(0, "Valid IP", "You have entered a valid IP") ; put your code here

    EndSwitch
        
WEnd

Share this post


Link to post
Share on other sites

wow - reading the help helps :)

_GUICtrlIpAddressClear Clears the contents of the IP address control

_GUICtrlIpAddressCreate Create a GUI IP Address Control

_GUICtrlIpAddressDelete Deletes the IpAddress control

_GUICtrlIpAddressGet Retrieves the address values for all four fields in the IP address control

_GUICtrlIpAddressIsBlank Determines if all fields in the IP address control are blank

_GUICtrlIpAddressSet Sets the address values for all four fields in the IP address control

_GUICtrlIpAddressSetFocus Sets the keyboard focus to the specified field in the IP address control.

_GUICtrlIpAddressSetFont Set the font for the control

_GUICtrlIpAddressSetRange Sets the valid range for the specified field in the IP address control

_GUICtrlIpAddressShowHide Shows/Hides the IP address control

Share this post


Link to post
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
Sign in to follow this  
Followers 0