Handle signal.me links
This commit is contained in:
parent
4273ddb6d0
commit
6f242eca57
9 changed files with 195 additions and 36 deletions
22
ts/util/isValidE164.ts
Normal file
22
ts/util/isValidE164.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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 <https://www.twilio.com/docs/glossary/what-e164#regex-matching-for-e164> and
|
||||
* <https://stackoverflow.com/a/23299989>.
|
||||
*/
|
||||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue