diff --git a/package-lock.json b/package-lock.json index 3499fd6..f5ad8ea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "dependencies": { "axios": "^1.7.0", + "libphonenumber-js": "^1.13.16", "lucide-react": "^0.460.0", "react": "^19.0.0", "react-dom": "^19.0.0" @@ -3455,6 +3456,12 @@ "node": ">= 0.8.0" } }, + "node_modules/libphonenumber-js": { + "version": "1.13.16", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.13.16.tgz", + "integrity": "sha512-tIOCM9yx2Go6d5/ZANe0K+G4AZek1Ymx81HxQpf19Sri4zMP95eQbKdnUGHAvFQ4nx0PeLhFqvAfisTADXj3tQ==", + "license": "MIT" + }, "node_modules/lightningcss": { "version": "1.32.0", "resolved": "https://registry.npmjs.org/lightningcss/-/lightningcss-1.32.0.tgz", diff --git a/package.json b/package.json index 52b54af..14dab7a 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ }, "dependencies": { "axios": "^1.7.0", + "libphonenumber-js": "^1.13.16", "lucide-react": "^0.460.0", "react": "^19.0.0", "react-dom": "^19.0.0" diff --git a/src/App.tsx b/src/App.tsx index cf5f5c3..24044a5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -20,20 +20,27 @@ import { ProfileDrawer } from './components/auth/ProfileDrawer'; import { PaymentSuccessModal } from './components/checkout/PaymentSuccessModal'; import { PasswordUpdatedModal } from './components/auth/PasswordUpdatedModal'; import { BillingPhoneModal } from './components/checkout/BillingPhoneModal'; +import { LoggedOutView } from './components/auth/LoggedOutView'; import { openMobileApp, DEFAULT_RETURN_ROUTE } from './utils/navigation'; -const getInitialTab = (): 'storefront' | 'subscriptions' => { +const getInitialTab = (): 'storefront' | 'subscriptions' | 'logged-out' => { if (typeof window !== 'undefined') { const path = window.location.pathname.toLowerCase(); + if (path.includes('/logged-out')) return 'logged-out'; if (path.includes('/subscriptions')) return 'subscriptions'; + + const params = new URLSearchParams(window.location.search); + if (params.get('logged_out') === 'true' || params.get('status') === 'logged-out') { + return 'logged-out'; + } } return 'storefront'; }; export default function App() { - const [activeTab, setActiveTab] = useState<'storefront' | 'subscriptions'>(getInitialTab); + const [activeTab, setActiveTab] = useState<'storefront' | 'subscriptions' | 'logged-out'>(getInitialTab); - const switchTab = (tab: 'storefront' | 'subscriptions') => { + const switchTab = (tab: 'storefront' | 'subscriptions' | 'logged-out') => { setActiveTab(tab); if (typeof window !== 'undefined') { const isStorePrefix = window.location.pathname.startsWith('/store'); @@ -149,60 +156,89 @@ export default function App() { const res = await axios.get(`${API_BASE}/api/plans`); if (Array.isArray(res.data)) { setPublicPlans(res.data); + fetchModuleCategories(res.data); } } catch (err) { console.error('Failed to load public plans:', err); } }; - // Dynamic Curriculum Modules with Live Categories + // Dynamic Curriculum Modules with Live Categories const [curriculumModules, setCurriculumModules] = useState(CURRICULUM_MODULES); - const fetchModuleCategories = async () => { + const fetchModuleCategories = async (plansList?: PublicPlan[]) => { try { const res = await axios.get(`${API_BASE}/api/contents/modules`); const apiModules: any[] = res.data?.modules || []; + const currentPlans = plansList && plansList.length > 0 ? plansList : publicPlans; if (apiModules.length > 0) { - const normalizeCategory = (cat?: string) => { + const normalizeCategory = (cat?: string): string | null => { if (!cat) return null; - const c = cat.toLowerCase(); + const c = cat.toLowerCase().trim(); if (c === 'point' || c === 'points') return 'Points'; - if (c === 'pattern' || c === 'patterns') return 'Pattern'; + if (c === 'pattern' || c === 'patterns' || c === 'five-elements') return 'Pattern'; if (c === 'nutrition') return 'Nutrition'; if (c === 'therapeutics' || c === 'therapeutic') return 'Therapeutics'; - return cat; + if (c === 'lifetime') return 'Lifetime'; + return cat.charAt(0).toUpperCase() + cat.slice(1); }; setCurriculumModules((prev) => prev.map((item) => { - const matched = apiModules.find((m) => { - const mCode = (m.code || '').toLowerCase(); + // 1. If item maps directly to a plan with single module slug, match by that slug + const matchedPlan = currentPlans.find((p) => p.code === item.code || p.base_code === item.code); + let matched: any = null; + if (matchedPlan) { + const slugs: string[] = matchedPlan.module_slugs || (matchedPlan.modules || []).map((m: any) => m.slug).filter(Boolean); + if (slugs.length === 1) { + const targetSlug = slugs[0].toLowerCase(); + matched = apiModules.find((m) => (m.slug || '').toLowerCase() === targetSlug); + } + } + + // 2. Direct code match + if (!matched) { const iCode = (item.code || '').toLowerCase(); - if (mCode && iCode && mCode === iCode) return true; - const slug = (m.slug || '').toLowerCase(); - const mName = (m.name || '').toLowerCase(); + matched = apiModules.find((m) => (m.code || '').toLowerCase() === iCode); + } + + // 3. Normalized semantic match without collisions + if (!matched) { const iName = item.name.toLowerCase(); - const cleanI = iName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim(); - const cleanM = mName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim(); - if (cleanI.includes('acu') && cleanM.includes('acupuncture') && !cleanI.includes('scalp') && !cleanI.includes('ear')) return true; - if (cleanI.includes('scalp') && cleanM.includes('scalp')) return true; - if (cleanI.includes('ear') && (cleanM.includes('ear') || slug.includes('auriculo'))) return true; - if (cleanI.includes('gyneco') && slug.includes('gyneco')) return true; - if (cleanI.includes('eight') && slug.includes('eight')) return true; - if (cleanI.includes('zang') && slug.includes('tcm-pattern')) return true; - if (cleanI.includes('qi') && slug.includes('qi')) return true; - if (cleanI.includes('pathogenic') && slug.includes('pathogenic')) return true; - if (cleanI.includes('six') && slug.includes('six')) return true; - if (cleanI.includes('four') && slug.includes('four')) return true; - if (cleanI.includes('three') && slug.includes('three')) return true; - if (cleanI.includes('five') && slug.includes('five')) return true; - if (cleanI.includes('food') && slug.includes('nutrition')) return true; - return false; - }); + matched = apiModules.find((m) => { + const mSlug = (m.slug || '').toLowerCase(); + const mName = (m.name || '').toLowerCase(); + const cleanM = mName.replace('points:', '').replace('therapeutics:', '').split('(')[0].trim(); - const updatedCat = normalizeCategory(matched?.metadata?.category || matched?.category); + if (cleanI.includes('scalp') && (cleanM.includes('scalp') || mSlug.includes('scalp'))) return true; + + // Disambiguate Ear Reflexology / Auriculotherapy vs Ear Acupuncture + if (cleanI.includes('reflexology') || item.code === 'THERAPEUTICS_EAR') { + return mSlug.includes('auriculo') || cleanM.includes('reflexology') || mSlug.includes('reflexology'); + } + if (cleanI.includes('ear') || item.code === 'POINTS_EAR') { + return mSlug.includes('ear-acupuncture') || (cleanM.includes('ear') && !mSlug.includes('auriculo') && !cleanM.includes('reflexology')); + } + + if (cleanI.includes('acu') && cleanM.includes('acupuncture') && !cleanI.includes('scalp') && !cleanI.includes('ear')) return true; + if (cleanI.includes('gyneco') && mSlug.includes('gyneco')) return true; + if (cleanI.includes('eight') && mSlug.includes('eight')) return true; + if (cleanI.includes('zang') && mSlug.includes('tcm-pattern')) return true; + if (cleanI.includes('qi') && mSlug.includes('qi')) return true; + if (cleanI.includes('pathogenic') && mSlug.includes('pathogenic')) return true; + if (cleanI.includes('six') && mSlug.includes('six')) return true; + if (cleanI.includes('four') && mSlug.includes('four')) return true; + if (cleanI.includes('three') && mSlug.includes('three')) return true; + if (cleanI.includes('five') && mSlug.includes('five')) return true; + if (cleanI.includes('food') && mSlug.includes('nutrition')) return true; + return false; + }); + } + + const rawCat = matched?.category || matched?.metadata?.category || matched?.metadata?.kind; + const updatedCat = normalizeCategory(rawCat); if (updatedCat) { return { ...item, category: updatedCat }; } @@ -251,6 +287,12 @@ export default function App() { const urlPlanCode = params.get('planCode'); const urlReturnRoute = params.get('returnRoute') || params.get('redirectPath') || params.get('redirect'); const urlScheme = params.get('scheme'); + const shouldOpenLogin = params.get('login') === 'true' || params.get('auth') === 'login'; + + if (shouldOpenLogin) { + setAuthMode('login'); + setShowAuthModal(true); + } if (urlReturnRoute) { setReturnRoute(urlReturnRoute); @@ -282,10 +324,15 @@ export default function App() { } } - if (urlToken || urlPlanCode) { + if (urlToken || urlPlanCode || shouldOpenLogin) { const isStorePrefix = window.location.pathname.startsWith('/store'); const basePath = isStorePrefix ? '/store/' : '/'; - const cleanPath = activeTab === 'subscriptions' ? `${basePath}subscriptions` : basePath; + const cleanPath = + activeTab === 'subscriptions' + ? `${basePath}subscriptions` + : activeTab === 'logged-out' + ? `${basePath}logged-out` + : basePath; window.history.replaceState({}, document.title, cleanPath); } @@ -354,13 +401,14 @@ export default function App() { setAppliedCoupon(null); setCouponCode(''); setPricingCalc(null); - switchTab('storefront'); setShowProfileDrawer(false); setProfileDisplayName(''); setProfilePhone(''); setProfileCountry('India'); setProfileError(null); setProfileSuccess(false); + setShowAuthModal(false); + switchTab('logged-out'); }; const handleUpdateProfile = async (e: React.FormEvent) => { @@ -379,7 +427,7 @@ export default function App() { setProfileSaving(false); return; } - cleanedPhoneToSave = formatE164Phone(parsed.dialCode, parsed.localDigits); + cleanedPhoneToSave = formatE164Phone(parsed.dialCode, parsed.localDigits, profileCountry); } try { @@ -472,8 +520,7 @@ export default function App() { setAuthLoading(false); return; } - const rawDigits = authPhone.replace(/\D/g, ''); - fullPhone = `${authDialCode}${rawDigits}`; + fullPhone = formatE164Phone(authDialCode, authPhone, authCountry); } const endpoint = authMode === 'login' ? '/api/auth/login' : '/api/auth/register'; @@ -510,6 +557,9 @@ export default function App() { setAuthEmail(''); setAuthDisplayName(''); setAuthPhone(''); + if (activeTab === 'logged-out') { + switchTab('storefront'); + } } catch (err: any) { setAuthError(err.response?.data?.detail || 'Authentication failed. Please check credentials.'); } finally { @@ -882,7 +932,7 @@ export default function App() { // Sanitize contact for Razorpay: strictly E.164 (+) const parsedContact = parsePhoneNumber(loggedInUser?.phone_number, loggedInUser?.country || 'India'); - const sanitizedContact = formatE164Phone(parsedContact.dialCode, parsedContact.localDigits); + const sanitizedContact = formatE164Phone(parsedContact.dialCode, parsedContact.localDigits, loggedInUser?.country || 'India'); const rzpOptions = { key: razorpayKeyId, @@ -1064,6 +1114,14 @@ export default function App() { /> + ) : activeTab === 'logged-out' ? ( + { + switchTab('storefront'); + setAuthMode('login'); + setShowAuthModal(true); + }} + /> ) : ( /* ๐Ÿงพ Tab: User Personal Subscriptions Ledger */ void; +} + +export const LoggedOutView: React.FC = ({ + onLoginAgain, +}) => { + const isStorePrefix = + typeof window !== 'undefined' && window.location.pathname.startsWith('/store'); + const basePath = isStorePrefix ? '/store/' : '/'; + const loginUrl = `${basePath}?login=true`; + const loginDisplayUrl = + typeof window !== 'undefined' + ? `${window.location.origin}${loginUrl}` + : loginUrl; + + return ( +
+
+ {/* Status Badge Icon */} +
+ +
+ + {/* Title & Description */} +

+ Successfully Logged Out +

+

+ You have been securely signed out of your AcuPedia session. Thank you for using our platform. +

+ + {/* Security Notice */} +
+ +

+ For security, please close your browser window if you are using a shared or public device. +

+
+ + {/* Actions */} + + + {/* Option to login in again via URL (explicit link for user / copy) */} + +
+
+ ); +}; + diff --git a/src/components/auth/ProfileDrawer.tsx b/src/components/auth/ProfileDrawer.tsx index adceaac..74011d0 100644 --- a/src/components/auth/ProfileDrawer.tsx +++ b/src/components/auth/ProfileDrawer.tsx @@ -94,7 +94,7 @@ export const ProfileDrawer: React.FC = ({ const handleLocalPhoneChange = (newLocal: string) => { setLocalPhone(newLocal); - setProfilePhone(newLocal ? formatE164Phone(dialCode, newLocal) : ''); + setProfilePhone(newLocal ? formatE164Phone(dialCode, newLocal, profileCountry) : ''); }; const handleDialCodeChange = (newCode: string, newCountry: string) => { @@ -107,6 +107,8 @@ export const ProfileDrawer: React.FC = ({ } setLocalPhone(''); setProfilePhone(''); + } else { + setProfilePhone(localPhone ? formatE164Phone(newCode, localPhone, profileCountry) : ''); } }; diff --git a/src/components/catalog/CatalogSection.tsx b/src/components/catalog/CatalogSection.tsx index 100f62b..f942b3d 100644 --- a/src/components/catalog/CatalogSection.tsx +++ b/src/components/catalog/CatalogSection.tsx @@ -176,7 +176,7 @@ export const CatalogSection: React.FC = ({ onClick={() => setShowLockedByCategory(prev => ({ ...prev, Pattern: !prev.Pattern }))} className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0" > - {showLockedByCategory.Pattern ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Pattern' && !isModuleUnlocked(m.code)).length}) + {showLockedByCategory.Pattern ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => (m.category === 'Pattern' || m.category === 'Patterns') && !isModuleUnlocked(m.code)).length}) @@ -191,7 +191,7 @@ export const CatalogSection: React.FC = ({
{(() => { - const items = curriculumModules.filter(m => m.category === 'Pattern'); + const items = curriculumModules.filter(m => m.category === 'Pattern' || m.category === 'Patterns'); const visible = items.filter(sub => { const isUnlocked = isModuleUnlocked(sub.code); const live = getModulePrice(sub); diff --git a/src/components/checkout/BillingPhoneModal.tsx b/src/components/checkout/BillingPhoneModal.tsx index 45e2d4d..8dc2b08 100644 --- a/src/components/checkout/BillingPhoneModal.tsx +++ b/src/components/checkout/BillingPhoneModal.tsx @@ -76,7 +76,7 @@ export const BillingPhoneModal: React.FC = ({ } setSaving(true); - const e164 = formatE164Phone(dialCode, phone); + const e164 = formatE164Phone(dialCode, phone, country); try { const success = await onSavePhone(e164, country); if (success) { diff --git a/src/components/common/PhoneInput.tsx b/src/components/common/PhoneInput.tsx index 7f7e60e..88be9b7 100644 --- a/src/components/common/PhoneInput.tsx +++ b/src/components/common/PhoneInput.tsx @@ -39,9 +39,10 @@ export const PhoneInput: React.FC = ({ const dropdownRef = useRef(null); const searchInputRef = useRef(null); - let activeRule = getCountryRuleByDialCode(dialCode); - if (!activeRule && country) { - activeRule = getCountryRuleByName(country); + // Prioritize country name if available, fallback to dial code + let activeRule = country ? getCountryRuleByName(country) : undefined; + if (!activeRule && dialCode) { + activeRule = getCountryRuleByDialCode(dialCode, country); } if (!activeRule) { activeRule = getCountryRuleByDialCode('+91')!; @@ -131,7 +132,7 @@ export const PhoneInput: React.FC = ({ const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length); const matched = sorted.find((c) => trimmed.startsWith(c.code)); if (matched) { - if (onDialCodeChange && matched.code !== dialCode) { + if (onDialCodeChange && (matched.code !== dialCode || matched.country !== country)) { onDialCodeChange(matched.code, matched.country); } const rest = trimmed.slice(matched.code.length).replace(/\D/g, ''); @@ -320,22 +321,11 @@ export const PhoneInput: React.FC = ({ />
- {/* Helper text or Error message */} -
- {error ? ( -

{error}

- ) : ( -

- {activeRule.label || activeRule.country}:{' '} - {activeRule.minLength === activeRule.maxLength - ? `Requires exactly ${activeRule.maxLength} digits` - : `${activeRule.minLength} to ${activeRule.maxLength} digits`} -

- )} - - {phone.length}/{activeRule.maxLength} - -
+ {error && ( +

+ {error} +

+ )} ); }; diff --git a/src/components/layout/StoreHeader.tsx b/src/components/layout/StoreHeader.tsx index d5c2547..b0194f0 100644 --- a/src/components/layout/StoreHeader.tsx +++ b/src/components/layout/StoreHeader.tsx @@ -3,8 +3,8 @@ import { Sparkles, LogIn, UserPlus, BookOpen, CheckCircle } from 'lucide-react'; import type { UserProfile } from '../../types'; interface StoreHeaderProps { - activeTab: 'storefront' | 'subscriptions'; - onSwitchTab: (tab: 'storefront' | 'subscriptions') => void; + activeTab: 'storefront' | 'subscriptions' | 'logged-out'; + onSwitchTab: (tab: 'storefront' | 'subscriptions' | 'logged-out') => void; loggedInUser: UserProfile | null; onOpenProfile: () => void; onOpenAuth: (mode: 'login' | 'register') => void; diff --git a/src/constants/countries.ts b/src/constants/countries.ts index 40eff4b..c179b4d 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -1,6 +1,8 @@ +import type { CountryCode as LibCountryCode } from 'libphonenumber-js'; import type { Currency } from '../types'; export interface CountryCode { + iso2: LibCountryCode; code: string; label: string; country: string; @@ -12,90 +14,90 @@ export interface CountryCode { export const COUNTRY_CODES: CountryCode[] = [ // South Asia - { code: '+91', label: '๐Ÿ‡ฎ๐Ÿ‡ณ +91', country: 'India', currency: 'INR', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+92', label: '๐Ÿ‡ต๐Ÿ‡ฐ +92', country: 'Pakistan', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+880', label: '๐Ÿ‡ง๐Ÿ‡ฉ +880', country: 'Bangladesh', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+94', label: '๐Ÿ‡ฑ๐Ÿ‡ฐ +94', country: 'Sri Lanka', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+977', label: '๐Ÿ‡ณ๐Ÿ‡ต +977', country: 'Nepal', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+975', label: '๐Ÿ‡ง๐Ÿ‡น +975', country: 'Bhutan', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+960', label: '๐Ÿ‡ฒ๐Ÿ‡ป +960', country: 'Maldives', currency: 'USD', minLength: 7, maxLength: 7, placeholder: '7-digit mobile number' }, + { iso2: 'IN', code: '+91', label: '๐Ÿ‡ฎ๐Ÿ‡ณ +91', country: 'India', currency: 'INR', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'PK', code: '+92', label: '๐Ÿ‡ต๐Ÿ‡ฐ +92', country: 'Pakistan', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'BD', code: '+880', label: '๐Ÿ‡ง๐Ÿ‡ฉ +880', country: 'Bangladesh', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'LK', code: '+94', label: '๐Ÿ‡ฑ๐Ÿ‡ฐ +94', country: 'Sri Lanka', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'NP', code: '+977', label: '๐Ÿ‡ณ๐Ÿ‡ต +977', country: 'Nepal', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'BT', code: '+975', label: '๐Ÿ‡ง๐Ÿ‡น +975', country: 'Bhutan', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { iso2: 'MV', code: '+960', label: '๐Ÿ‡ฒ๐Ÿ‡ป +960', country: 'Maldives', currency: 'USD', minLength: 7, maxLength: 7, placeholder: '7-digit mobile number' }, // North America - { code: '+1', label: '๐Ÿ‡บ๐Ÿ‡ธ +1', country: 'United States', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit phone number' }, - { code: '+1', label: '๐Ÿ‡จ๐Ÿ‡ฆ +1', country: 'Canada', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit phone number' }, - { code: '+52', label: '๐Ÿ‡ฒ๐Ÿ‡ฝ +52', country: 'Mexico', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'US', code: '+1', label: '๐Ÿ‡บ๐Ÿ‡ธ +1', country: 'United States', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit phone number' }, + { iso2: 'CA', code: '+1', label: '๐Ÿ‡จ๐Ÿ‡ฆ +1', country: 'Canada', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit phone number' }, + { iso2: 'MX', code: '+52', label: '๐Ÿ‡ฒ๐Ÿ‡ฝ +52', country: 'Mexico', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, // Europe & UK - { code: '+44', label: '๐Ÿ‡ฌ๐Ÿ‡ง +44', country: 'United Kingdom', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+49', label: '๐Ÿ‡ฉ๐Ÿ‡ช +49', country: 'Germany', currency: 'EUR', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+33', label: '๐Ÿ‡ซ๐Ÿ‡ท +33', country: 'France', currency: 'EUR', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, - { code: '+39', label: '๐Ÿ‡ฎ๐Ÿ‡น +39', country: 'Italy', currency: 'EUR', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, - { code: '+34', label: '๐Ÿ‡ช๐Ÿ‡ธ +34', country: 'Spain', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+31', label: '๐Ÿ‡ณ๐Ÿ‡ฑ +31', country: 'Netherlands', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+41', label: '๐Ÿ‡จ๐Ÿ‡ญ +41', country: 'Switzerland', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+32', label: '๐Ÿ‡ง๐Ÿ‡ช +32', country: 'Belgium', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' }, - { code: '+43', label: '๐Ÿ‡ฆ๐Ÿ‡น +43', country: 'Austria', currency: 'EUR', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+353', label: '๐Ÿ‡ฎ๐Ÿ‡ช +353', country: 'Ireland', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+46', label: '๐Ÿ‡ธ๐Ÿ‡ช +46', country: 'Sweden', currency: 'EUR', minLength: 7, maxLength: 10, placeholder: '7 to 10 digits' }, - { code: '+47', label: '๐Ÿ‡ณ๐Ÿ‡ด +47', country: 'Norway', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+45', label: '๐Ÿ‡ฉ๐Ÿ‡ฐ +45', country: 'Denmark', currency: 'EUR', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+358', label: '๐Ÿ‡ซ๐Ÿ‡ฎ +358', country: 'Finland', currency: 'EUR', minLength: 7, maxLength: 10, placeholder: '7 to 10 digits' }, - { code: '+351', label: '๐Ÿ‡ต๐Ÿ‡น +351', country: 'Portugal', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+30', label: '๐Ÿ‡ฌ๐Ÿ‡ท +30', country: 'Greece', currency: 'EUR', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+48', label: '๐Ÿ‡ต๐Ÿ‡ฑ +48', country: 'Poland', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+420', label: '๐Ÿ‡จ๐Ÿ‡ฟ +420', country: 'Czech Republic', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+36', label: '๐Ÿ‡ญ๐Ÿ‡บ +36', country: 'Hungary', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+40', label: '๐Ÿ‡ท๐Ÿ‡ด +40', country: 'Romania', currency: 'EUR', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, - { code: '+380', label: '๐Ÿ‡บ๐Ÿ‡ฆ +380', country: 'Ukraine', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+354', label: '๐Ÿ‡ฎ๐Ÿ‡ธ +354', country: 'Iceland', currency: 'EUR', minLength: 7, maxLength: 9, placeholder: '7 to 9 digits' }, - { code: '+352', label: '๐Ÿ‡ฑ๐Ÿ‡บ +352', country: 'Luxembourg', currency: 'EUR', minLength: 8, maxLength: 10, placeholder: '8 to 10 digits' }, - { code: '+385', label: '๐Ÿ‡ญ๐Ÿ‡ท +385', country: 'Croatia', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' }, - { code: '+421', label: '๐Ÿ‡ธ๐Ÿ‡ฐ +421', country: 'Slovakia', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+359', label: '๐Ÿ‡ง๐Ÿ‡ฌ +359', country: 'Bulgaria', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' }, - { code: '+7', label: '๐Ÿ‡ท๐Ÿ‡บ +7', country: 'Russia', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+90', label: '๐Ÿ‡น๐Ÿ‡ท +90', country: 'Turkey', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'GB', code: '+44', label: '๐Ÿ‡ฌ๐Ÿ‡ง +44', country: 'United Kingdom', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { iso2: 'DE', code: '+49', label: '๐Ÿ‡ฉ๐Ÿ‡ช +49', country: 'Germany', currency: 'EUR', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { iso2: 'FR', code: '+33', label: '๐Ÿ‡ซ๐Ÿ‡ท +33', country: 'France', currency: 'EUR', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { iso2: 'IT', code: '+39', label: '๐Ÿ‡ฎ๐Ÿ‡น +39', country: 'Italy', currency: 'EUR', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { iso2: 'ES', code: '+34', label: '๐Ÿ‡ช๐Ÿ‡ธ +34', country: 'Spain', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'NL', code: '+31', label: '๐Ÿ‡ณ๐Ÿ‡ฑ +31', country: 'Netherlands', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'CH', code: '+41', label: '๐Ÿ‡จ๐Ÿ‡ญ +41', country: 'Switzerland', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'BE', code: '+32', label: '๐Ÿ‡ง๐Ÿ‡ช +32', country: 'Belgium', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' }, + { iso2: 'AT', code: '+43', label: '๐Ÿ‡ฆ๐Ÿ‡น +43', country: 'Austria', currency: 'EUR', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { iso2: 'IE', code: '+353', label: '๐Ÿ‡ฎ๐Ÿ‡ช +353', country: 'Ireland', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'SE', code: '+46', label: '๐Ÿ‡ธ๐Ÿ‡ช +46', country: 'Sweden', currency: 'EUR', minLength: 7, maxLength: 10, placeholder: '7 to 10 digits' }, + { iso2: 'NO', code: '+47', label: '๐Ÿ‡ณ๐Ÿ‡ด +47', country: 'Norway', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { iso2: 'DK', code: '+45', label: '๐Ÿ‡ฉ๐Ÿ‡ฐ +45', country: 'Denmark', currency: 'EUR', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { iso2: 'FI', code: '+358', label: '๐Ÿ‡ซ๐Ÿ‡ฎ +358', country: 'Finland', currency: 'EUR', minLength: 7, maxLength: 10, placeholder: '7 to 10 digits' }, + { iso2: 'PT', code: '+351', label: '๐Ÿ‡ต๐Ÿ‡น +351', country: 'Portugal', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'GR', code: '+30', label: '๐Ÿ‡ฌ๐Ÿ‡ท +30', country: 'Greece', currency: 'EUR', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'PL', code: '+48', label: '๐Ÿ‡ต๐Ÿ‡ฑ +48', country: 'Poland', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'CZ', code: '+420', label: '๐Ÿ‡จ๐Ÿ‡ฟ +420', country: 'Czech Republic', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'HU', code: '+36', label: '๐Ÿ‡ญ๐Ÿ‡บ +36', country: 'Hungary', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'RO', code: '+40', label: '๐Ÿ‡ท๐Ÿ‡ด +40', country: 'Romania', currency: 'EUR', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { iso2: 'UA', code: '+380', label: '๐Ÿ‡บ๐Ÿ‡ฆ +380', country: 'Ukraine', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'IS', code: '+354', label: '๐Ÿ‡ฎ๐Ÿ‡ธ +354', country: 'Iceland', currency: 'EUR', minLength: 7, maxLength: 9, placeholder: '7 to 9 digits' }, + { iso2: 'LU', code: '+352', label: '๐Ÿ‡ฑ๐Ÿ‡บ +352', country: 'Luxembourg', currency: 'EUR', minLength: 8, maxLength: 10, placeholder: '8 to 10 digits' }, + { iso2: 'HR', code: '+385', label: '๐Ÿ‡ญ๐Ÿ‡ท +385', country: 'Croatia', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' }, + { iso2: 'SK', code: '+421', label: '๐Ÿ‡ธ๐Ÿ‡ฐ +421', country: 'Slovakia', currency: 'EUR', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'BG', code: '+359', label: '๐Ÿ‡ง๐Ÿ‡ฌ +359', country: 'Bulgaria', currency: 'EUR', minLength: 8, maxLength: 9, placeholder: '8 to 9 digits' }, + { iso2: 'RU', code: '+7', label: '๐Ÿ‡ท๐Ÿ‡บ +7', country: 'Russia', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'TR', code: '+90', label: '๐Ÿ‡น๐Ÿ‡ท +90', country: 'Turkey', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, // Asia-Pacific - { code: '+61', label: '๐Ÿ‡ฆ๐Ÿ‡บ +61', country: 'Australia', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, - { code: '+64', label: '๐Ÿ‡ณ๐Ÿ‡ฟ +64', country: 'New Zealand', currency: 'USD', minLength: 8, maxLength: 10, placeholder: '8 to 10 digits' }, - { code: '+81', label: '๐Ÿ‡ฏ๐Ÿ‡ต +81', country: 'Japan', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+86', label: '๐Ÿ‡จ๐Ÿ‡ณ +86', country: 'China', currency: 'USD', minLength: 11, maxLength: 11, placeholder: '11-digit mobile number' }, - { code: '+82', label: '๐Ÿ‡ฐ๐Ÿ‡ท +82', country: 'South Korea', currency: 'USD', minLength: 9, maxLength: 11, placeholder: '9 to 11 digits' }, - { code: '+852', label: '๐Ÿ‡ญ๐Ÿ‡ฐ +852', country: 'Hong Kong', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+886', label: '๐Ÿ‡น๐Ÿ‡ผ +886', country: 'Taiwan', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+65', label: '๐Ÿ‡ธ๐Ÿ‡ฌ +65', country: 'Singapore', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+60', label: '๐Ÿ‡ฒ๐Ÿ‡พ +60', country: 'Malaysia', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, - { code: '+62', label: '๐Ÿ‡ฎ๐Ÿ‡ฉ +62', country: 'Indonesia', currency: 'USD', minLength: 9, maxLength: 12, placeholder: '9 to 12 digits' }, - { code: '+63', label: '๐Ÿ‡ต๐Ÿ‡ญ +63', country: 'Philippines', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+66', label: '๐Ÿ‡น๐Ÿ‡ญ +66', country: 'Thailand', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+84', label: '๐Ÿ‡ป๐Ÿ‡ณ +84', country: 'Vietnam', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { iso2: 'AU', code: '+61', label: '๐Ÿ‡ฆ๐Ÿ‡บ +61', country: 'Australia', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { iso2: 'NZ', code: '+64', label: '๐Ÿ‡ณ๐Ÿ‡ฟ +64', country: 'New Zealand', currency: 'USD', minLength: 8, maxLength: 10, placeholder: '8 to 10 digits' }, + { iso2: 'JP', code: '+81', label: '๐Ÿ‡ฏ๐Ÿ‡ต +81', country: 'Japan', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { iso2: 'CN', code: '+86', label: '๐Ÿ‡จ๐Ÿ‡ณ +86', country: 'China', currency: 'USD', minLength: 11, maxLength: 11, placeholder: '11-digit mobile number' }, + { iso2: 'KR', code: '+82', label: '๐Ÿ‡ฐ๐Ÿ‡ท +82', country: 'South Korea', currency: 'USD', minLength: 9, maxLength: 11, placeholder: '9 to 11 digits' }, + { iso2: 'HK', code: '+852', label: '๐Ÿ‡ญ๐Ÿ‡ฐ +852', country: 'Hong Kong', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { iso2: 'TW', code: '+886', label: '๐Ÿ‡น๐Ÿ‡ผ +886', country: 'Taiwan', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'SG', code: '+65', label: '๐Ÿ‡ธ๐Ÿ‡ฌ +65', country: 'Singapore', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { iso2: 'MY', code: '+60', label: '๐Ÿ‡ฒ๐Ÿ‡พ +60', country: 'Malaysia', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { iso2: 'ID', code: '+62', label: '๐Ÿ‡ฎ๐Ÿ‡ฉ +62', country: 'Indonesia', currency: 'USD', minLength: 9, maxLength: 12, placeholder: '9 to 12 digits' }, + { iso2: 'PH', code: '+63', label: '๐Ÿ‡ต๐Ÿ‡ญ +63', country: 'Philippines', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'TH', code: '+66', label: '๐Ÿ‡น๐Ÿ‡ญ +66', country: 'Thailand', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'VN', code: '+84', label: '๐Ÿ‡ป๐Ÿ‡ณ +84', country: 'Vietnam', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, // Middle East - { code: '+971', label: '๐Ÿ‡ฆ๐Ÿ‡ช +971', country: 'UAE', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+966', label: '๐Ÿ‡ธ๐Ÿ‡ฆ +966', country: 'Saudi Arabia', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+974', label: '๐Ÿ‡ถ๐Ÿ‡ฆ +974', country: 'Qatar', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+965', label: '๐Ÿ‡ฐ๐Ÿ‡ผ +965', country: 'Kuwait', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+968', label: '๐Ÿ‡ด๐Ÿ‡ฒ +968', country: 'Oman', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+973', label: '๐Ÿ‡ง๐Ÿ‡ญ +973', country: 'Bahrain', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, - { code: '+972', label: '๐Ÿ‡ฎ๐Ÿ‡ฑ +972', country: 'Israel', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+962', label: '๐Ÿ‡ฏ๐Ÿ‡ด +962', country: 'Jordan', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+961', label: '๐Ÿ‡ฑ๐Ÿ‡ง +961', country: 'Lebanon', currency: 'USD', minLength: 7, maxLength: 8, placeholder: '7 to 8 digits' }, + { iso2: 'AE', code: '+971', label: '๐Ÿ‡ฆ๐Ÿ‡ช +971', country: 'UAE', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'SA', code: '+966', label: '๐Ÿ‡ธ๐Ÿ‡ฆ +966', country: 'Saudi Arabia', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'QA', code: '+974', label: '๐Ÿ‡ถ๐Ÿ‡ฆ +974', country: 'Qatar', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { iso2: 'KW', code: '+965', label: '๐Ÿ‡ฐ๐Ÿ‡ผ +965', country: 'Kuwait', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { iso2: 'OM', code: '+968', label: '๐Ÿ‡ด๐Ÿ‡ฒ +968', country: 'Oman', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { iso2: 'BH', code: '+973', label: '๐Ÿ‡ง๐Ÿ‡ญ +973', country: 'Bahrain', currency: 'USD', minLength: 8, maxLength: 8, placeholder: '8-digit mobile number' }, + { iso2: 'IL', code: '+972', label: '๐Ÿ‡ฎ๐Ÿ‡ฑ +972', country: 'Israel', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'JO', code: '+962', label: '๐Ÿ‡ฏ๐Ÿ‡ด +962', country: 'Jordan', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'LB', code: '+961', label: '๐Ÿ‡ฑ๐Ÿ‡ง +961', country: 'Lebanon', currency: 'USD', minLength: 7, maxLength: 8, placeholder: '7 to 8 digits' }, // Latin America - { code: '+55', label: '๐Ÿ‡ง๐Ÿ‡ท +55', country: 'Brazil', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+54', label: '๐Ÿ‡ฆ๐Ÿ‡ท +54', country: 'Argentina', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+56', label: '๐Ÿ‡จ๐Ÿ‡ฑ +56', country: 'Chile', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+57', label: '๐Ÿ‡จ๐Ÿ‡ด +57', country: 'Colombia', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+51', label: '๐Ÿ‡ต๐Ÿ‡ช +51', country: 'Peru', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'BR', code: '+55', label: '๐Ÿ‡ง๐Ÿ‡ท +55', country: 'Brazil', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { iso2: 'AR', code: '+54', label: '๐Ÿ‡ฆ๐Ÿ‡ท +54', country: 'Argentina', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { iso2: 'CL', code: '+56', label: '๐Ÿ‡จ๐Ÿ‡ฑ +56', country: 'Chile', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'CO', code: '+57', label: '๐Ÿ‡จ๐Ÿ‡ด +57', country: 'Colombia', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'PE', code: '+51', label: '๐Ÿ‡ต๐Ÿ‡ช +51', country: 'Peru', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, // Africa - { code: '+27', label: '๐Ÿ‡ฟ๐Ÿ‡ฆ +27', country: 'South Africa', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, - { code: '+234', label: '๐Ÿ‡ณ๐Ÿ‡ฌ +234', country: 'Nigeria', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, - { code: '+254', label: '๐Ÿ‡ฐ๐Ÿ‡ช +254', country: 'Kenya', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+233', label: '๐Ÿ‡ฌ๐Ÿ‡ญ +233', country: 'Ghana', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+20', label: '๐Ÿ‡ช๐Ÿ‡ฌ +20', country: 'Egypt', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, - { code: '+212', label: '๐Ÿ‡ฒ๐Ÿ‡ฆ +212', country: 'Morocco', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, - { code: '+230', label: '๐Ÿ‡ฒ๐Ÿ‡บ +230', country: 'Mauritius', currency: 'USD', minLength: 7, maxLength: 8, placeholder: '7 to 8 digits' }, + { iso2: 'ZA', code: '+27', label: '๐Ÿ‡ฟ๐Ÿ‡ฆ +27', country: 'South Africa', currency: 'USD', minLength: 9, maxLength: 10, placeholder: '9 to 10 digits' }, + { iso2: 'NG', code: '+234', label: '๐Ÿ‡ณ๐Ÿ‡ฌ +234', country: 'Nigeria', currency: 'USD', minLength: 10, maxLength: 11, placeholder: '10 to 11 digits' }, + { iso2: 'KE', code: '+254', label: '๐Ÿ‡ฐ๐Ÿ‡ช +254', country: 'Kenya', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'GH', code: '+233', label: '๐Ÿ‡ฌ๐Ÿ‡ญ +233', country: 'Ghana', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'EG', code: '+20', label: '๐Ÿ‡ช๐Ÿ‡ฌ +20', country: 'Egypt', currency: 'USD', minLength: 10, maxLength: 10, placeholder: '10-digit mobile number' }, + { iso2: 'MA', code: '+212', label: '๐Ÿ‡ฒ๐Ÿ‡ฆ +212', country: 'Morocco', currency: 'USD', minLength: 9, maxLength: 9, placeholder: '9-digit mobile number' }, + { iso2: 'MU', code: '+230', label: '๐Ÿ‡ฒ๐Ÿ‡บ +230', country: 'Mauritius', currency: 'USD', minLength: 7, maxLength: 8, placeholder: '7 to 8 digits' }, ]; // Alphabetically sorted list of countries (A-Z) @@ -105,29 +107,23 @@ export const SORTED_COUNTRY_CODES: CountryCode[] = [...COUNTRY_CODES].sort((a, b export const DEFAULT_COUNTRY = COUNTRY_CODES[0]; // India (+91) -export const getCountryRuleByDialCode = (dialCode: string): CountryCode => { - return ( - COUNTRY_CODES.find((c) => c.code === dialCode) || { - code: dialCode, - label: dialCode, - country: 'Other', - currency: 'USD', - minLength: 7, - maxLength: 15, - placeholder: 'Phone number', - } - ); +export const getCountryRuleByIso = (iso?: string | null): CountryCode => { + if (!iso) return DEFAULT_COUNTRY; + const upper = iso.toUpperCase().trim(); + return COUNTRY_CODES.find((c) => c.iso2 === upper) || DEFAULT_COUNTRY; }; -export const getCountryRuleByName = (countryName: string): CountryCode => { +export const getCountryRuleByName = (countryName?: string | null): CountryCode => { if (!countryName) return DEFAULT_COUNTRY; const normalized = countryName.toLowerCase().trim(); return ( COUNTRY_CODES.find( (c) => c.country.toLowerCase() === normalized || + c.iso2.toLowerCase() === normalized || normalized.includes(c.country.toLowerCase()) ) || { + iso2: 'IN', code: '+91', label: '๐Ÿ‡ฎ๐Ÿ‡ณ +91', country: countryName, @@ -138,3 +134,26 @@ export const getCountryRuleByName = (countryName: string): CountryCode => { } ); }; + +export const getCountryRuleByDialCode = (dialCode?: string | null, countryHint?: string | null): CountryCode => { + if (!dialCode) return DEFAULT_COUNTRY; + // If country hint is given, try resolving by country first + if (countryHint) { + const byCountry = getCountryRuleByName(countryHint); + if (byCountry && byCountry.code === dialCode) { + return byCountry; + } + } + return ( + COUNTRY_CODES.find((c) => c.code === dialCode) || { + iso2: 'IN', + code: dialCode, + label: dialCode, + country: countryHint || 'Other', + currency: 'USD', + minLength: 7, + maxLength: 15, + placeholder: 'Phone number', + } + ); +}; diff --git a/src/types/index.ts b/src/types/index.ts index 1d7ce6b..bf73f81 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -85,6 +85,7 @@ export interface PublicPlan { subtitle?: string; description?: string; modules?: Array<{ id?: string; name: string; slug?: string }>; + module_slugs?: string[]; } export interface VerificationResult { diff --git a/src/utils/validation.ts b/src/utils/validation.ts index f7bc4c0..59d2625 100644 --- a/src/utils/validation.ts +++ b/src/utils/validation.ts @@ -1,4 +1,11 @@ -import { COUNTRY_CODES, getCountryRuleByDialCode, getCountryRuleByName } from '../constants/countries'; +import { parsePhoneNumberFromString, type CountryCode as LibCountryCode } from 'libphonenumber-js/max'; +import { + COUNTRY_CODES, + getCountryRuleByDialCode, + getCountryRuleByName, + getCountryRuleByIso, + DEFAULT_COUNTRY, +} from '../constants/countries'; /** * Strips non-numeric / non-phone characters from text in real-time @@ -15,8 +22,8 @@ export const cleanPhoneInput = (text: string, maxLength = 15, allowPlus = true): }; /** - * Validates phone number according to country rules (e.g. India = exactly 10 digits) - * Strictly disallows alphabetic characters and invalid symbols + * Validates mobile phone number according to country telecom numbering plans. + * Uses libphonenumber-js to enforce mobile prefixes (e.g., France 06/07, India 6-9, UK 07). */ export const validatePhoneNumber = ( val?: string | null, @@ -31,8 +38,8 @@ export const validatePhoneNumber = ( return 'Phone number cannot contain alphabetic characters.'; } - // Strictly disallow hyphens, dashes, and invalid characters - if (/[\-()_]/.test(trimmed)) { + // Strictly disallow hyphens, dashes, and invalid symbols + if (/[\-_()/[\]]/.test(trimmed)) { return 'Phone number cannot contain hyphens or special symbols.'; } @@ -46,69 +53,89 @@ export const validatePhoneNumber = ( return 'Please enter a valid phone number with numeric digits.'; } - // Resolve country rule by country name first, or fallback to dial code + // Resolve country rule: prioritize explicit country name, fallback to dialCode let rule = country ? getCountryRuleByName(country) : undefined; - if (!rule || rule.country === 'Other') { - rule = dialCode ? getCountryRuleByDialCode(dialCode) : undefined; + if ((!rule || rule.country === 'Other') && dialCode) { + rule = getCountryRuleByDialCode(dialCode, country); } - // If still not found and input starts with '+', match from COUNTRY_CODES - if (!rule && trimmed.startsWith('+')) { - const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length); - rule = sorted.find((c) => trimmed.startsWith(c.code)); + if (!rule) { + rule = DEFAULT_COUNTRY; } - // Default to India if no specific rule resolved and dial code is +91 or country is India - if (!rule || rule.country === 'Other') { - if (dialCode === '+91' || (country && country.toLowerCase() === 'india')) { - rule = getCountryRuleByDialCode('+91'); + + const iso2 = rule.iso2 || 'IN'; + + // Extract national digits without dial code prefix + let nationalDigits = allDigits; + const dialDigits = rule.code.replace(/\D/g, ''); + if (trimmed.startsWith('+')) { + if (allDigits.startsWith(dialDigits)) { + nationalDigits = allDigits.slice(dialDigits.length); } + } else if (allDigits.startsWith(dialDigits) && allDigits.length > rule.maxLength) { + nationalDigits = allDigits.slice(dialDigits.length); } - if (rule && rule.country !== 'Other') { - const dialDigits = rule.code.replace(/\D/g, ''); - let localDigits = allDigits; + const digitsWithoutTrunk0 = nationalDigits.startsWith('0') && iso2 !== 'IT' + ? nationalDigits.replace(/^0+/, '') + : nationalDigits; - if (trimmed.startsWith('+')) { - // Input includes country code prefix (e.g. +919876543210 or +9198765432) - // Must strip the dial code to extract the actual local number - if (allDigits.startsWith(dialDigits)) { - localDigits = allDigits.slice(dialDigits.length); - } - } else if (allDigits.length > rule.maxLength && allDigits.startsWith(dialDigits)) { - // Input was formatted with dial digits without '+' and exceeds local maxLength (e.g. 919876543210) - localDigits = allDigits.slice(dialDigits.length); + // 1. Enforce length validation FIRST so digit count errors take precedence over prefix errors + if (iso2 === 'IN') { + if (nationalDigits.length !== 10) { + return 'India mobile number must be exactly 10 digits.'; } - + if (!/^[6-9]/.test(nationalDigits)) { + return 'India mobile number must begin with 6, 7, 8, or 9.'; + } + } else if (iso2 === 'FR') { + if (nationalDigits.length < 9) { + return 'France mobile number is too short (must be 9 digits, or 10 digits with 0).'; + } + if (nationalDigits.length > 10 || (nationalDigits.length === 10 && !nationalDigits.startsWith('0'))) { + return 'France mobile number cannot exceed 9 digits (or 10 digits with leading 0).'; + } + if (!/^[67]/.test(digitsWithoutTrunk0)) { + return 'France mobile number must begin with 06 or 07 (or 6 or 7).'; + } + } else if (iso2 === 'GB') { + if (digitsWithoutTrunk0.length < 10) { + return 'United Kingdom mobile number is too short (must be 10 digits, or 11 digits with 0).'; + } + if (digitsWithoutTrunk0.length > 10) { + return 'United Kingdom mobile number cannot exceed 10 digits (or 11 digits with leading 0).'; + } + if (!/^7/.test(digitsWithoutTrunk0)) { + return 'United Kingdom mobile number must begin with 07 (or 7).'; + } + } else { + // General length check for other countries if (rule.minLength === rule.maxLength) { - if (localDigits.length !== rule.minLength) { - return `${rule.country} phone number must be exactly ${rule.minLength} digits.`; + if (digitsWithoutTrunk0.length !== rule.minLength && nationalDigits.length !== rule.minLength) { + return `${rule.country} mobile number must be exactly ${rule.minLength} digits.`; } } else { - if (localDigits.length < rule.minLength) { - return `${rule.country} phone number must be at least ${rule.minLength} digits.`; + if (digitsWithoutTrunk0.length < rule.minLength && nationalDigits.length < rule.minLength) { + return `${rule.country} mobile number is too short (min ${rule.minLength} digits).`; } - if (localDigits.length > rule.maxLength) { - return `${rule.country} phone number cannot exceed ${rule.maxLength} digits.`; + if (digitsWithoutTrunk0.length > rule.maxLength) { + return `${rule.country} mobile number cannot exceed ${rule.maxLength} digits.`; } } + } - // Specific country telecom prefix rules - if (dialDigits === '91' || rule.country === 'India') { - if (!/^[6-9]/.test(localDigits)) { - return 'India mobile number must begin with 6, 7, 8, or 9.'; - } + // 2. Validate telecom numbering rules with libphonenumber-js + const candidate = trimmed.startsWith('+') ? trimmed : `${rule.code}${nationalDigits}`; + const parsed = parsePhoneNumberFromString(candidate, iso2); + + if (parsed && parsed.isValid()) { + const numberType = parsed.getType(); + if (numberType === 'FIXED_LINE') { + return `Please enter a valid mobile number for ${rule.country}.`; } - return null; } - // General fallback ITU E.164 - if (allDigits.length < 7) { - return 'Phone number must contain at least 7 digits.'; - } - if (allDigits.length > 15) { - return 'Phone number cannot exceed 15 digits.'; - } - return null; + return `Please enter a valid mobile number for ${rule.country} (e.g. ${rule.placeholder}).`; }; export const isValidPhoneNumber = ( @@ -125,14 +152,34 @@ export const isValidPhoneNumber = ( export const parsePhoneNumber = ( fullPhone?: string | null, fallbackCountry = 'India' -): { country: string; dialCode: string; localDigits: string } => { - const defaultRule = getCountryRuleByName(fallbackCountry) || getCountryRuleByDialCode('+91')!; +): { country: string; dialCode: string; localDigits: string; iso2: LibCountryCode } => { + const defaultRule = getCountryRuleByName(fallbackCountry) || DEFAULT_COUNTRY; if (!fullPhone || !fullPhone.trim()) { - return { country: defaultRule.country, dialCode: defaultRule.code, localDigits: '' }; + return { + country: defaultRule.country, + dialCode: defaultRule.code, + localDigits: '', + iso2: defaultRule.iso2, + }; } - const trimmed = fullPhone.trim(); - // Try matching dial code prefixes from longest to shortest + const trimmed = fullPhone.trim(); + const parsed = parsePhoneNumberFromString(trimmed, defaultRule.iso2); + + if (parsed) { + const matchedRule = parsed.country + ? getCountryRuleByIso(parsed.country) + : getCountryRuleByDialCode(`+${parsed.countryCallingCode}`, fallbackCountry); + + return { + country: matchedRule.country, + dialCode: `+${parsed.countryCallingCode}`, + localDigits: parsed.nationalNumber, + iso2: matchedRule.iso2, + }; + } + + // Fallback regex match from longest dial code const sorted = [...COUNTRY_CODES].sort((a, b) => b.code.length - a.code.length); // If fallbackCountry is specified and matches the prefix, prioritize it @@ -142,6 +189,7 @@ export const parsePhoneNumber = ( country: defaultRule.country, dialCode: defaultRule.code, localDigits: rawLocal.slice(0, defaultRule.maxLength), + iso2: defaultRule.iso2, }; } @@ -152,34 +200,44 @@ export const parsePhoneNumber = ( country: matched.country, dialCode: matched.code, localDigits: rawLocal.slice(0, matched.maxLength), + iso2: matched.iso2, }; } - // If no '+' prefix, check if digits start with fallback country dial digits and exceed national length - const dialDigits = defaultRule.code.replace(/\D/g, ''); const rawDigits = trimmed.replace(/\D/g, ''); - let local = rawDigits; - if ( - dialDigits && - rawDigits.startsWith(dialDigits) && - rawDigits.length > defaultRule.maxLength - ) { - local = rawDigits.slice(dialDigits.length); - } return { country: defaultRule.country, dialCode: defaultRule.code, - localDigits: local.slice(0, defaultRule.maxLength), + localDigits: rawDigits.slice(0, defaultRule.maxLength), + iso2: defaultRule.iso2, }; }; /** - * Formats full phone number cleanly as E.164 without spaces (+) + * Formats full phone number cleanly as E.164 without spaces (+), + * automatically stripping any national trunk '0' where appropriate. */ -export const formatE164Phone = (dialCode: string, localDigits: string): string => { - const digits = localDigits.replace(/\D/g, ''); +export const formatE164Phone = (dialCode: string, localDigits: string, country?: string): string => { + if (!localDigits || !localDigits.trim()) return ''; + const rule = country ? getCountryRuleByName(country) : getCountryRuleByDialCode(dialCode, country); + const rawDigits = localDigits.replace(/\D/g, ''); + if (!rawDigits) return ''; + const code = dialCode.startsWith('+') ? dialCode : `+${dialCode}`; - return digits ? `${code}${digits}` : ''; + const candidate = localDigits.startsWith('+') ? localDigits : `${code}${rawDigits}`; + + const parsed = parsePhoneNumberFromString(candidate, rule.iso2); + if (parsed && parsed.isValid()) { + return parsed.format('E.164'); + } + + // Fallback: If starts with trunk 0 and country is not one that keeps trunk 0 (like Italy) + let cleanLocal = rawDigits; + if (rule.iso2 !== 'IT' && cleanLocal.startsWith('0')) { + cleanLocal = cleanLocal.replace(/^0+/, ''); + } + + return `${code}${cleanLocal}`; }; /** @@ -197,27 +255,8 @@ export const updatePhoneDialCode = ( const oldRule = getCountryRuleByName(oldCountry); const newRule = getCountryRuleByName(newCountry); - let nationalDigits = ''; - if (trimmed.startsWith('+')) { - const matched = [...COUNTRY_CODES] - .sort((a, b) => b.code.length - a.code.length) - .find((c) => trimmed.startsWith(c.code)); - if (matched) { - nationalDigits = trimmed.slice(matched.code.length).replace(/\D/g, ''); - } else { - nationalDigits = trimmed.replace(/^\+/, '').replace(/\D/g, ''); - } - } else { - const oldDialDigits = oldRule.code.replace(/\D/g, ''); - const rawDigits = trimmed.replace(/\D/g, ''); - if (oldDialDigits && rawDigits.startsWith(oldDialDigits) && rawDigits.length > oldDialDigits.length) { - nationalDigits = rawDigits.slice(oldDialDigits.length); - } else { - nationalDigits = rawDigits; - } - } - - const bounded = nationalDigits.slice(0, newRule.maxLength); + const parsed = parsePhoneNumber(trimmed, oldRule.country); + const bounded = parsed.localDigits.slice(0, newRule.maxLength); return bounded ? `${newRule.code} ${bounded}` : `${newRule.code} `; }; @@ -259,8 +298,6 @@ export const validatePassword = (password: string, fieldName = 'Password'): stri /** * RFC 5322 & RFC 1035 compliant email validation regex. - * Disallows invalid domain characters (e.g. + in domain like +gmail+.com, consecutive dots, leading/trailing hyphens) - * while properly accepting plus-addressing in local-part (e.g. sanskar+sarak@gmail.com). */ export const EMAIL_REGEX = /^[a-zA-Z0-9_%+-]+(?:\.[a-zA-Z0-9_%+-]+)*@[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*\.[a-zA-Z]{2,}$/; @@ -277,4 +314,3 @@ export const validateEmail = (email?: string | null): string | null => { export const isValidEmail = (email?: string | null): boolean => { return validateEmail(email) === null; }; -