// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only /** * Returns `true` if the input looks like a valid E164, and `false` otherwise. Note that * this may return false positives, as it is a fairly naïve check. * * See and * . */ export function isValidE164( value: unknown, mustStartWithPlus: boolean ): value is string { if (typeof value !== 'string') { return false; } const regex = mustStartWithPlus ? /^\+[1-9]\d{1,14}$/ : /^\+?[1-9]\d{1,14}$/; return regex.test(value); }