15 lines
571 B
JavaScript
15 lines
571 B
JavaScript
import { isValidPhoneNumber } from "libphonenumber-js/max";
|
|
|
|
export const phoneError =
|
|
"Bitte eine gültige Telefonnummer mit Vorwahl eingeben, z. B. 0170 1234567 oder +49 170 1234567.";
|
|
|
|
export function isValidBookingPhone(value) {
|
|
if (typeof value !== "string" || value.length > 50) return false;
|
|
if (/[\x00-\x1f\x7f]/.test(value)) return false;
|
|
const phone = value.trim();
|
|
if (!phone) return true;
|
|
if (!/^\+?[0-9 ()/.-]+$/.test(phone)) return false;
|
|
if (!/^(?:\+|0)/.test(phone)) return false;
|
|
return isValidPhoneNumber(phone, "DE");
|
|
}
|