[Tutor] Validating String contains IP address

Alan Gauld alan.gauld at yahoo.co.uk
Fri Mar 31 19:52:34 EDT 2017

On 01/04/17 00:35, Ed Manning wrote:
> What's the best way to validate a string contains a IP address 

It depends on how thorough you want to be.
You can define a regex to check that its 4 groups of numbers
separated by periods.

Or you can split the string into fields and validate that
the values are each less than 255

Or you could try connecting to it and see if you get a

How sure do you need to be?

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list