Sign in to follow this  
Followers 0
jagreenwood

Validation on inputbox()

7 posts in this topic

Hi Guys,

I've got an AutoIt script that installs and configures another app. During the installation process I'm popping up a box with inputbox() for the user to enter the IP address of a server. I haven't been able to figure out a way to validate the input is in an IP address format(xxx.xxx.xxx.xxx).

Does anyone have any ideas on how I might be able to accomplish this?

Thanks!!

Share this post


Link to post
Share on other sites



Hi Guys,

I've got an AutoIt script that installs and configures another app. During the installation process I'm popping up a box with inputbox() for the user to enter the IP address of a server. I haven't been able to figure out a way to validate the input is in an IP address format(xxx.xxx.xxx.xxx).

Does anyone have any ideas on how I might be able to accomplish this?

Thanks!!

You could apply a bunch of string manipulation, starting with StringSplit($sInputIP, "."), etc.

The other option is StringRegExp(), but that requires more experience.

:P


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

Share this post


Link to post
Share on other sites

\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b

thats the regular expression to make sure all numbers are between 0 and 255


[font="Impact"] I always thought dogs laid eggs, and I learned something today. [/font]

Share this post


Link to post
Share on other sites

It's not that a good RegExp won't work (and get you Geek Points), but this is easier to read, and easier to add more conditions to:

While 1
    $sInputIP = InputBox("IP", "Input IP: ")
    If @error Then ExitLoop
    $avSplit = StringSplit($sInputIP, ".")
    If $avSplit[0] = 4 Then
        For $n = 1 To 4
            $Octet = Number($avSplit[$n])
            If ($Octet < 0) Or ($Octet > 255) Then ContinueLoop 2
            If ($n = 1) And ($Octet = 0) Then ContinueLoop 2
        Next
        ExitLoop
    EndIf
WEnd

If $sInputIP <> "" Then MsgBox(64, "Valid IP", $sInputIP)

:P


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

Share this post


Link to post
Share on other sites

@

Why doen't you use a "_GUICtrlIpAddressCreate" ?

#include <GuiIPAddress.au3>

Opt("MustDeclareVars", 1)

_Main()

Func _Main()
    Local $msg, $hgui, $clear, $getaddress, $isblank, $button, $hIPAddress
    
    $hgui = GUICreate("IP Address Control Create Example", 300, 150)
    
    $hIPAddress = _GUICtrlIpAddressCreate ($hgui, 10, 10, 125, 30, $WS_THICKFRAME)
    
    $clear = GUICtrlCreateButton("Clear IP", 10, 50, 80, 20)
    $getaddress = GUICtrlCreateButton("Get IP", 95, 50, 80, 20)
    $isblank = GUICtrlCreateButton("Is Blank?", 180, 50, 80, 20)
    
    $button = GUICtrlCreateButton("Exit", 100, 100, 100, 25)
    _GUICtrlIpAddressSet ($hIPAddress, "24.168.2.128")
    GUISetState(@SW_SHOW)
    
    While 1
        $msg = GUIGetMsg()
        
        Select
            
            Case $msg = $GUI_EVENT_CLOSE Or $msg = $button
                Exit
            Case $msg = $clear
                _GUICtrlIpAddressClear ($hIPAddress)
            Case $msg = $getaddress
                MsgBox(0, "IP Entered", _GUICtrlIpAddressGet ($hIPAddress))
            Case $msg = $isblank
                If _GUICtrlIpAddressIsBlank ($hIPAddress) Then
                    MsgBox(0, "Fields Check", "All IP Fields are blank")
                Else
                    MsgBox(0, "Fields Check", "NOT All IP Fields are blank")
                EndIf
        EndSelect
    WEnd
EndFunc   ;==>_Main

regards,

ptrex

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