8

I have an dialog for HTTP proxy configuration with hostname and port edit boxes.

My question is how can I validate user input for correct hostname and port?

May be I have to use some regular expression for hostname validation or there is some helpful MFC or WinAPI function? What is the maximum correct number for port?

Julian Popov
  • 17,401
  • 12
  • 55
  • 81

2 Answers2

11
  1. Port number is an unsigned short from 1-65535, ports under 1024 are reserved for system services http, ftp, etc.
  2. I don't believe that you can validate host name (or should) especially when you have locallized host names.
Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87
2

You can use Apache Commons Validator's InetAddressValidator. Check out http://commons.apache.org/proper/commons-validator/apidocs/org/apache/commons/validator/routines/InetAddressValidator.html.

That project has many validator utilities you can reuse. Hope it helps.

The_Cute_Hedgehog
  • 1,280
  • 13
  • 22