Last active
August 8, 2018 14:40
-
-
Save keepitsimple/70fbc875548e2dd5aaa5ca280e708a10 to your computer and use it in GitHub Desktop.
JavaScript the best RegEx for IPv4 validation with test examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ip4RegEx = /^(?:(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\.(?!$)|$)){4}$/ | |
/* | |
//valid | |
127.0.0.1 | |
192.168.1.1 | |
192.168.1.255 | |
255.255.255.255 | |
0.0.0.0 | |
1.1.1.1 | |
//invalid | |
01.1.1.1 | |
1.01.1.1 | |
1.1.01.1 | |
1.1.1.01 | |
192.168.1.1. | |
192.168.1.1.1 | |
30.168.1.255.1 | |
127.1 | |
192.168.1.256 | |
-1.2.3.4 | |
3...3 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment