Home  >  Article  >  Web Front-end  >  How to implement regular expression verification port range in js

How to implement regular expression verification port range in js

王林
王林forward
2020-04-17 09:14:302930browse

How to implement regular expression verification port range in js

javascript regular expression to verify the port legitimacy of the IP address

if (!(/^[1-9]\d*$/.test(port) && 1 <= 1 * port && 1 * port <= 65535)){
 return false
}

Tips:

Your port does not comply with the range: 0-65535

Let’s take a look at the JavaScript (Js) regular expression to verify the IP port number. The code is as follows:

var ip="192.168.2.1:8080"
 var pattIp=/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\:([0-9]|[1-9]\d{1,3}|[1-5]\d{4}|6[0-5]{2}[0-3][0-5])$/;
 if(pattIp.test(ip)==false)
 {
 return false;
 }

Recommended tutorial: js tutorial

The above is the detailed content of How to implement regular expression verification port range in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete