Home > Web Front-end > JS Tutorial > body text

How to implement regular expression verification port range in js

王林
Release: 2020-04-17 09:14:30
forward
2962 people have browsed it

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
}
Copy after login

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;
 }
Copy after login

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!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!