Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to verify the validity of ip address by javascript

Shulou Source: shulou.com Published: 2022-05-31 11:46:54 10月01日 Update

This article mainly introduces the relevant knowledge of javascript how to verify whether the ip address is legal, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this javascript article on how to verify whether the ip address is legal. Let's take a look.

Javascript verifies that the ip address is legal: first create a js sample file; then verify that the ip address is legal through the js regular expression, such as "function isValidIP (ip) {...}".

This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.

How does javascript verify that the ip address is legal?

Js regular expression validates legal IP addresses

The code is as follows:

Function isValidIP (ip) {var reg = / ^ (\ d {1 return reg.test 2} | 1\ d\ d | 2 [0-4]\ d | 25 [0-5])\. (\ d {0-4] 2} | 1\ d\ d | 2 [0-4]\ d | 25 [0-5])\. (\ d {0-4]\ d | 2 [0-4]\ d | 25 [0-5])\. (\ d {1J 2} | 1\ d\ d | 2 [0-4]\ d | 25 [0-5]) } let a = isValidIP ('10.10.10.1111') console.log (a) this is the end of the article on "how to verify whether the ip address is valid by javascript". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to verify the legality of ip addresses by javascript". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Legal address knowledge code content regular article expression value easy to operate file article method easy to understand more environment computer see example system Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS OPPO Reno Shulou Tech Info Redmi