mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-30 11:02:16 +00:00
feat(console): phone number validation with flags (#5139)
Formats the phonenumber according to the preselected country
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { CountryCode, parsePhoneNumber } from 'libphonenumber-js';
|
||||
|
||||
export function formatPhone(phone: string): { phone: string; country: CountryCode } {
|
||||
const defaultCountry = 'CH';
|
||||
|
||||
if (phone) {
|
||||
try {
|
||||
const phoneNumber = parsePhoneNumber(phone, defaultCountry);
|
||||
const country = phoneNumber.country ?? defaultCountry;
|
||||
if (phoneNumber) {
|
||||
return { phone: phoneNumber.formatInternational(), country };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
return { phone, country: defaultCountry };
|
||||
}
|
||||
Reference in New Issue
Block a user