JS Validation IP:Port

前端 未结 5 1015
既然无缘
既然无缘 2020-12-06 22:09

I have a question, on how to validate IP:Port together. example:

192.158.2.10:80 <--Valid

192.158.2.10 <---Invalid

So the port is a must, I fo

5条回答
  •  无人及你
    2020-12-06 22:15

    You can simply use the Regex below to validate IP:Port only

    Valid IP Address (0.0.0.0 - 255.255.255.255): Valid port (1-65535)

    /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):(6553[0-5]|655[0-2][0-9]|65[0-4][0-9][0-9]|6[0-4][0-9][0-9][0-9][0-9]|[1-5](\d){4}|[1-9](\d){0,3})$/

提交回复
热议问题