-
February 13th, 2011, 08:21 AM
#1
[RESOLVED] Input Validation for an IP address
Hello all,
I'm trying to validate the input for an IP address. I'm getting a little bit tied up on the logic of it...
The only thing I can really come up with is this:
-Take the IP address in as a char[]
-Parse to check for the correct format and number of decimal points
-Split it into four ints representing each octet
-check that the ints are within the valid range
I feel like there is a much better way to go about this...If anybody has done this before any help would be appreciated!
Of course, I could always compile a list of all IP addresses and compare an input string to each one...I flirted with this idea enough to make a quick program to output all IP addresses sequentially into a TXT file. I left it running for about 2 hours and had still only written less than 2% of all IP addresses!!
-
February 13th, 2011, 10:18 AM
#2
Re: Input Validation for an IP address
Originally Posted by Austin.Soucy
Hello all,
I'm trying to validate the input for an IP address. I'm getting a little bit tied up on the logic of it...
The only thing I can really come up with is this:
-Take the IP address in as a char[]
-Parse to check for the correct format and number of decimal points
-Split it into four ints representing each octet
-check that the ints are within the valid range
I feel like there is a much better way to go about this...If anybody has done this before any help would be appreciated!
If you're using C++, and your compiler has regular expression support (#include <regex>), then use that.
An IP address validation can be done using a regular expression -- just google it and you will see what it is.
http://www.google.com/#sclient=psy&h...b08d9a0d602c0a
Regards,
Paul McKenzie
-
February 13th, 2011, 02:32 PM
#3
Re: Input Validation for an IP address
This is exactly what I needed thank you!
Interestingly enough, this thread shows up on your google search already. Last one on the first page!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|