bitburner-src/utils/helpers/isValidIPAddress.ts

12 lines
416 B
TypeScript
Raw Normal View History

/**
* Checks whether a IP Address string is valid.
* @param ipaddress A string representing a potential IP Address
*/
2021-05-01 09:17:31 +02:00
export function isValidIPAddress(ipaddress: string): boolean {
2021-09-05 01:09:30 +02:00
const byteRange = "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)";
const regexStr = `^${byteRange}\.${byteRange}\.${byteRange}\.${byteRange}$`;
const ipAddressRegex = new RegExp(regexStr);
2021-09-05 01:09:30 +02:00
return ipAddressRegex.test(ipaddress);
}