Is there a way to check a valid host:port combination using regex and php?
The regular expression has to make sure that:
hostis a valid IP (containing four 1-3 digit numbers separated by 3 dots, number in range of 1-255)- there is a delimiter
: portis a valid number between 0 and 65535- nothing else is allowed
Examples of valid combinations:
-
95.241.1.5:5423
-
2.8.5.2:65532
Examples of INvalid combinations:
-
1.2345.12.1:5441
-
15.852.32.455:151896841
-
65.112.15.32:48trololo
should work, but it’s not pretty trying to match numbers with regexes…
In verbose format, a bit more readable: