diff --git a/es/lib/isIP.js b/es/lib/isIP.js index db05e7369..9280d8766 100644 --- a/es/lib/isIP.js +++ b/es/lib/isIP.js @@ -29,7 +29,7 @@ import assertString from './util/assertString'; to the 5th link, and "interface10" belongs to the 10th organization. * * */ -var ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; +var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; var ipv6Block = /^[0-9A-F]{1,4}$/i; export default function isIP(str) { var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; diff --git a/lib/isIP.js b/lib/isIP.js index 13f7ebc3f..b5a924cfd 100644 --- a/lib/isIP.js +++ b/lib/isIP.js @@ -38,7 +38,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs to the 5th link, and "interface10" belongs to the 10th organization. * * */ -var ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; +var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; var ipv6Block = /^[0-9A-F]{1,4}$/i; function isIP(str) { diff --git a/src/lib/isIP.js b/src/lib/isIP.js index 38141760a..a9a805781 100644 --- a/src/lib/isIP.js +++ b/src/lib/isIP.js @@ -28,7 +28,7 @@ import assertString from './util/assertString'; where the interface "ne0" belongs to the 1st link, "pvc1.3" belongs to the 5th link, and "interface10" belongs to the 10th organization. * * */ -const ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; +const ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; const ipv6Block = /^[0-9A-F]{1,4}$/i; export default function isIP(str, version = '') { diff --git a/test/validators.js b/test/validators.js index f660f0f28..fc9b1446f 100644 --- a/test/validators.js +++ b/test/validators.js @@ -734,11 +734,16 @@ describe('Validators', () => { '0.0.0.0', '255.255.255.255', '1.2.3.4', + '255.0.0.1', + '0.0.1.1', ], invalid: [ '::1', '2001:db8:0000:1:1:1:1:1', '::ffff:127.0.0.1', + '137.132.10.01', + '0.256.0.256', + '255.256.255.256', ], }); test({