diff --git a/frontend/src/lib/components/ui/phone-input/PhoneInput.svelte b/frontend/src/lib/components/ui/phone-input/PhoneInput.svelte new file mode 100644 index 0000000..570db7e --- /dev/null +++ b/frontend/src/lib/components/ui/phone-input/PhoneInput.svelte @@ -0,0 +1,103 @@ + + +
+ + {#if error} +

{error}

+ {/if} +
diff --git a/frontend/src/lib/components/ui/phone-input/index.ts b/frontend/src/lib/components/ui/phone-input/index.ts new file mode 100644 index 0000000..21ce8ae --- /dev/null +++ b/frontend/src/lib/components/ui/phone-input/index.ts @@ -0,0 +1,3 @@ +import PhoneInput from './PhoneInput.svelte'; + +export { PhoneInput }; diff --git a/frontend/src/lib/utils/phone.ts b/frontend/src/lib/utils/phone.ts index 0baa24c..8e052c5 100644 --- a/frontend/src/lib/utils/phone.ts +++ b/frontend/src/lib/utils/phone.ts @@ -22,18 +22,18 @@ export function isValidUKPhone(phone: string): boolean { export function formatPhoneDisplay(value: string): string { const clean = normalisePhoneInput(value); if (clean.startsWith('+44')) { - const digits = clean.slice(3); + const digits = clean.slice(3).slice(0, 10); // max 10 digits after +44 if (digits.length <= 4) return '+44 ' + digits; if (digits.length <= 8) return '+44 ' + digits.slice(0, 4) + ' ' + digits.slice(4); return '+44 ' + digits.slice(0, 4) + ' ' + digits.slice(4, 10); } if (clean.startsWith('0')) { - const digits = clean.slice(1); + const digits = clean.slice(1).slice(0, 10); // max 10 digits after 0 if (digits.length <= 4) return '0' + digits; if (digits.length <= 7) return '0' + digits.slice(0, 4) + ' ' + digits.slice(4); return '0' + digits.slice(0, 4) + ' ' + digits.slice(4, 10); } - return clean; + return clean.slice(0, 15); // fallback limit } /**