isValidPort property

bool get isValidPort

Checks if the string is a valid port number (1 - 65535)

Example:

String port = "8080";
print(port.isValidPort); // true
String invalidPort = "70000";
print(invalidPort.isValidPort); // false

Implementation

bool get isValidPort {
  final port = int.tryParse(this);
  return port != null && port > 0 && port <= 65535;
}