App directory #4

This commit is contained in:
Darren Clarke 2023-06-28 12:55:24 +00:00 committed by GitHub
parent 69706053c6
commit 4d743c5e67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 223 additions and 107 deletions

View file

@ -1,30 +0,0 @@
import { regex } from "react-admin";
export const E164Regex = /^\+[1-9]\d{1,14}$/;
/**
* Returns true if the number is a valid E164 number
*/
export const isValidE164Number = (phoneNumber: string) =>
E164Regex.test(phoneNumber);
/**
* Given a phone number approximation, will clean out whitespace and punctuation.
*/
export const sanitizeE164Number = (phoneNumber: string) => {
if (!phoneNumber) return "";
if (!phoneNumber.trim()) return "";
const sanitized = phoneNumber
.replaceAll(/\s/g, "")
.replaceAll(".", "")
.replaceAll("-", "")
.replaceAll("(", "")
.replaceAll(")", "");
if (sanitized[0] !== "+") return `+${sanitized}`;
return sanitized;
};
export const validateE164Number = regex(
E164Regex,
"Must start with a + and have no punctunation and no spaces."
);