mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-26 19:12:50 +00:00
feat: implement input length constraints and enhanced validation for international phone numbers
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { isValidPhoneNumber } from 'libphonenumber-js';
|
||||
import { resolveTokenFromStorage } from '../../session';
|
||||
import type {
|
||||
Bilingual,
|
||||
@@ -526,6 +527,13 @@ export function validateSections(
|
||||
}
|
||||
if (empty) continue;
|
||||
|
||||
// PhoneInput emits E.164 while typing, so a half-typed "+2519" is a
|
||||
// non-empty string that still has to be caught here.
|
||||
if (field.type === 'PHONE' && !isValidPhoneNumber(String(value))) {
|
||||
errors[`${section.key}.${field.key}`] = 'Enter a valid phone number';
|
||||
continue;
|
||||
}
|
||||
|
||||
const numeric = Number(value);
|
||||
if (!Number.isNaN(numeric)) {
|
||||
if (field.min !== undefined && numeric < field.min) {
|
||||
|
||||
Reference in New Issue
Block a user