CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2010
    Posts
    68

    [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!!

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Input Validation for an IP address

    Quote Originally Posted by Austin.Soucy View Post
    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

  3. #3
    Join Date
    Oct 2010
    Posts
    68

    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
  •  





Click Here to Expand Forum to Full Width

Featured