I have an situation that let the user input IP address through GUI, I can't find IP address input control in wxwidgets, should I use a text control instead for inputing, how can I validate that the user input valid IP address?
Or is there some exist code for IP address input control, please help me, thanks.[/b]
Is there an IP address input control? Topic is solved
If you're using wxPython, you can use the masked text control I believe for this; a C++ version of this control was partially developped this summer during google summer of code, but I gather it's not ready
Otherwise you can probably just use a text control with a custom validator
Otherwise you can probably just use a text control with a custom validator
"Keyboard not detected. Press F1 to continue"
-- Windows
-- Windows
Re: Is there an IP address input control?
For this kind of things, regex does it!Byron0914 wrote:[...]how can I validate that the user input valid IP address?
Code: Select all
// check of IP address
// regular expression for IP address (4 [0-255] decimal numbers separated by periods)
// [0-9]{1} : exactly 1 decimal digit ([0-9])
// |[0-9]{2} : ...or exactly 2 decimal digits ([10-99])
// |[0-1][0-9]{2} : ...or '0'/'1' followed by exactly 2 decimal digits ([000-199])
// |2[0-4][0-9] : ...or 2 followed by '0'/'1'/'2'/'3'/'4' followed by 1 decimal digit ([200-249])
// |25[0-5] : ...or '25' followed by '0'/'1'/'2'/'3'/'4'/'5' ([250-255])
// (([0-9]{1}|[0-9]{2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])\\.) : ...the whole followed by '.' (quoted)
// (([0-9]{1}|[0-9]{2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3} : ...the whole exactly 3 times
// ^(([0-9]{1}|[0-9]{2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3} : ...positioned at start
// ([0-9]{1}|[0-9]{2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5]) : [0-9] + [10-99] + [000-199] + [200-249] + [250-255]
// ([0-9]{1}|[0-9]{2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])$ : ...positioned at the end
wxRegEx regxIPAddr("^(([0-9]{1}|[0-9]{2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]{1}|[0-9]{2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])$");
if ( !regxIPAddr.Matches(ipAddress) ) {
...
}
Code: Select all
//* definition of IP Addresses text validator
wxString ipAddressFilter[11] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "."}; // authorized characters for IP Address
wxArrayString arraystrIPAddress(11, macAddressFilter);
wxTextValidator txtvldIPAddress(wxFILTER_INCLUDE_CHAR_LIST); // text validator for IP Address
txtvldIPAddress.SetIncludes(arraystrIPAddress); // sets authorized characters for IP Address
//* drawing of GUI
this->txtctrlIPAddress = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, txtvldIPAddress); // displays IP Address edit textcontrol
this->txtctrIPAddress->SetToolTip("Four [0-255] decimal numbers separated by periods\nFormat: A.B.C.D\nEx.: 192.168.1.1");