From 57cf92f4a68510b598927e96163f4cce5d75c309 Mon Sep 17 00:00:00 2001 From: Urvish Date: Mon, 26 Oct 2026 16:14:21 +0530 Subject: [PATCH] fix(validation): standardize phone validation to 7-15 digits --- src/components/auth/ProfileDrawer.tsx | 2 +- src/constants/countries.ts | 6 +++--- src/utils/validation.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/auth/ProfileDrawer.tsx b/src/components/auth/ProfileDrawer.tsx index df3febf..3f40f5c 100644 --- a/src/components/auth/ProfileDrawer.tsx +++ b/src/components/auth/ProfileDrawer.tsx @@ -148,7 +148,7 @@ export const ProfileDrawer: React.FC = ({ setProfilePhone(cleanPhoneInput(e.target.value, 16, true))} + onChange={(e) => setProfilePhone(cleanPhoneInput(e.target.value, 15, true))} placeholder={activeRule.placeholder} maxLength={16} className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500" diff --git a/src/constants/countries.ts b/src/constants/countries.ts index c3158aa..52acd95 100644 --- a/src/constants/countries.ts +++ b/src/constants/countries.ts @@ -39,7 +39,7 @@ export const COUNTRY_CODES: CountryCode[] = [ { 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: 6, maxLength: 10, placeholder: '6 to 10 digits' }, + { 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' }, @@ -107,7 +107,7 @@ export const getCountryRuleByDialCode = (dialCode: string): CountryCode => { label: dialCode, country: 'Other', currency: 'USD', - minLength: 6, + minLength: 7, maxLength: 15, placeholder: 'Phone number', } @@ -127,7 +127,7 @@ export const getCountryRuleByName = (countryName: string): CountryCode => { label: '🇮🇳 +91', country: countryName, currency: normalized === 'india' ? 'INR' : 'USD', - minLength: 6, + minLength: 7, maxLength: 15, placeholder: 'Phone number', } diff --git a/src/utils/validation.ts b/src/utils/validation.ts index aa90cdc..9876a97 100644 --- a/src/utils/validation.ts +++ b/src/utils/validation.ts @@ -5,7 +5,7 @@ import { getCountryRuleByDialCode, getCountryRuleByName } from '../constants/cou * If maxLength is provided, strictly restricts digit length * If allowPlus is false, strips any '+' symbols as well (for local number inputs) */ -export const cleanPhoneInput = (text: string, maxLength?: number, allowPlus = true): string => { +export const cleanPhoneInput = (text: string, maxLength = 15, allowPlus = true): string => { const trimmedStart = text.trimStart(); const hasPlus = allowPlus && trimmedStart.startsWith('+'); const rest = hasPlus ? trimmedStart.slice(1) : text; @@ -82,8 +82,8 @@ export const validatePhoneNumber = ( } // General fallback ITU E.164 - if (allDigits.length < 6) { - return 'Phone number must contain at least 6 digits.'; + if (allDigits.length < 7) { + return 'Phone number must contain at least 7 digits.'; } if (allDigits.length > 15) { return 'Phone number cannot exceed 15 digits.'; -- 2.34.1