How to use the isIP function from validator
Find comprehensive JavaScript validator.isIP code examples handpicked from public code repositorys.
7 8 9 10 11 12 13 14 15 16
console.log('https://github.com/chriso/validator.js\n', 'isURL', validator.isURL('https://github.com/chriso/validator.js')); console.log('127.0.0.1\n', 'isIP', validator.isIP('127.0.0.1')); console.log('2001:DB8:2de:0:0:0:0:e13\n', 'isIP', validator.isIP('2001:DB8:2de:0:0:0:0:e13')); console.log('127001\n', 'isIP', validator.isIP('127001')); console.log('4716368472599727\n', 'isCreditCard', validator.isCreditCard('4716368472599727')); console.log('4321\n', 'isCreditCard', validator.isCreditCard('4321'));
15
3
4
+ 5 other calls in file
96 97 98 99 100 101 102 103 104 105
}, ip: function(x) { check(x, "an IP address", validator.isIP(x)); }, ipv4: function(x) { check(x, "an IPv4 address", validator.isIP(x, 4)); }, ipv6: function(x) { check(x, "an IPv6 address", validator.isIP(x, 6)); },
2
4
0
+ 2 other calls in file
GitHub: bevacqua/infer
77 78 79 80 81 82 83 84 85 86
}; validator.isIP = function (str, version) { version = validator.toString(version); if (!version) { return validator.isIP(str, 4) || validator.isIP(str, 6); } else if (version === '4') { if (!ipv4Maybe.test(str)) { return false; }
2
3
4
746 747 748 749 750 751 752 753 754 755
// At least some OS accept the last 32 bits of an IPv6 address // (i.e. 2 of the blocks) in IPv4 notation, and RFC 3493 says // that '::ffff:a.b.c.d' is valid for IPv4-mapped IPv6 addresses, // and '::a.b.c.d' is deprecated, but also valid. var foundIPv4TransitionBlock = validator.isIP(blocks[blocks.length - 1], 4); var expectedNumberOfBlocks = foundIPv4TransitionBlock ? 7 : 8; if (blocks.length > expectedNumberOfBlocks) return false;
0
2
1
+ 3 other calls in file
GitHub: justinsisley/marshall
235 236 237 238 239 240 241 242 243 244
case 'float': isValid = validator.isFloat(stringValue); break; case 'ip': isValid = validator.isIP(stringValue); break; case 'phone': isValid = validator.isMobilePhone(stringValue, this.locale || 'en-US');
0
2
1
+ 31 other calls in file
44 45 46 47 48 49 50 51 52 53
} return true; }, isIP: function(rule, value) { if (rule) { return validator.isIP(value); } return true; }, isAlpha: function(rule, value) {
0
2
2
+ 5 other calls in file
71 72 73 74 75 76 77 78 79 80
isHexColor: validator.isHexColor, // isHexadecimal(str) - check if the string is a hexadecimal number. isHexadecimal: validator.isHexadecimal, // isIP(str [, version]) - check if the string is an IP (version 4 or 6). isIP: function (str, version) { return validator.isIP(str, typeof version !== 'boolean' ? version : undefined); }, // isISBN(str [, version]) - check if the string is an ISBN (version 10 or 13). isISBN: function (str, version) { return validator.isISBN(str, typeof version !== 'boolean' ? version : undefined);
0
1
3
+ 17 other calls in file
32 33 34 35 36 37 38 39 40 41 42 43 44
} // Validate IP address exports.validateIP = (ip) => { return validator.isIP(ip); } // Validate credit card number
0
0
0
36 37 38 39 40 41 42 43 44
response = await prompts({ type: 'text', name: 'value', message: 'Your public ip address', validate: (e) => isIP(e) || `Must be a valid ip address`, }); backendOutput['PUBLIC_IP_ADDRESS'] = response.value;
0
0
0
109 110 111 112 113 114 115 116 117 118
'ipv4': { method: (val) => V.isIP(val, 4), message: 'IPV4 string' }, 'ipv6': { method: (val) => V.isIP(val, 6), message: 'IPV6 string' }, // check if the string is an ISBN (version 10 or 13). 'isbn': {
0
0
0
validator.escape is the most popular function in validator (548 examples)