@azizbecha/strkit
Version:
strkit is a utility library offering a collection of essential string functions including validation, case conversion, truncation, and more. Ideal for both JavaScript and TypeScript developers to simplify string operations in their applications.
19 lines • 782 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = isIPv4Address;
/**
* Validates whether a given string is a valid IPv4 address.
*
* @param str - The string to check if it's a valid IPv4 address.
* @returns A boolean indicating whether the string is a valid IPv4 address.
*
* @example
* isIPv4Address("192.168.1.1"); // Output: true
* isIPv4Address("256.256.256.256"); // Output: false
* isIPv4Address("not-an-ip"); // Output: false
*/
function isIPv4Address(str) {
const ipv4Regex = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
return ipv4Regex.test(str);
}
//# sourceMappingURL=isIPv4Address.js.map