A port is a communication endpoint associated with a specific address
A port is a 16-bit unsigned integer ranging from
The regex pattern tries to figure out if the input string falls under the given range.
A Better approach
Although this works, a far better(and simpler) approach would be this:
- Take the input string and convert it into a number
- If possible see if it falls in the range
- If both the conditions succeed, then it is a valid port number