How to achive IP address validation for Taxteditor?


#1

I am using TextEditor for taking input which is IP address. How should i validate ip address that user hasn't entered a invalid ip address.? Is there any function exist in juce Liabrary for that.? Thanks in advance..


#2

No.. Haven't got anything to parse IP addresses, I'm afraid.


#3

https://github.com/vinniefalco/Beast/blob/master/beast/net/impl/IPAddress.cpp#L448


#4

Thanks TheVinn that worked.


#5

Hi guys,
my apologies for necroing this old thread.
Any chance you could post the code for your validation? The link is dead.
Cheers.


#6

No need to add externals any longer:
IPAddress

But looking at the code, I have no idea what happens, if the string is not a valid ip address…

HTH


#7

Ah nice, didn’t notice there was an IPAddress class.

Yes, seems like an isValid() method could be helpful.
I suppose I can something like this, though it feels dirty:

TextEditor::Listener::textEditorFocusLost(TextEditor& myTextEditor)
{
	IPAddress ip = IPAddress(myTextEditor.getText());
	if (ip.toString() == myTextEditor.getText())
	{
		// Entered IP address is valid.
		// ...
	}
}