extracted a function to validate a port number to be used from others we'll add in the future.