HomeRegex LibraryTCP / UDP Network Port (1-65535) Regex
100% Client-Side β€’ 0 B Data Leaves Browser
validation

TCP / UDP Network Port (1-65535) Regex

Validates network port numbers strictly between 1 and 65,535.

Regular Expression Pattern:
/^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/
Valid Match Example:
8080
Invalid / Non-Match Example:
70000

Regex Syntax Breakdown & Explanation

  • β€’Matches all valid 16-bit unsigned integer port boundaries up to 65535 without leading zeros.

Implementation in Popular Languages

JavaScript / TypeScript
const regex = /^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/;
const isValid = regex.test("8080");
console.log(isValid); // true
Python (re)
import re

pattern = r"^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$"
match = re.match(pattern, "8080")
print(bool(match)) # True
Go (regexp)
package main
import (
  "fmt"
  "regexp"
)

func main() {
  re := regexp.MustCompile(`^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$`)
  fmt.Println(re.MatchString("8080"))
}
Frequently Asked Questions

Frequently Asked Questions

Everything you need to know regarding specifications, syntax, and security best practices.

The regular expression pattern is /^([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$/. Validates network port numbers strictly between 1 and 65,535.