AFFiNE/packages/common/env/src/is-valid-ip-address.ts

9 lines
303 B
TypeScript
Raw Normal View History

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
);
}