AFFiNE/packages/common/env/src/is-valid-ip-address.ts
2023-10-18 15:30:08 +00:00

9 lines
303 B
TypeScript

export function isValidIPAddress(address: string) {
if (address === 'localhost') {
return true;
}
return /^(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]?)$/.test(
address
);
}