Merge pull request 'fix(validation): standardize phone validation to 7-15 digits' (#70) from phone-code into main

Reviewed-on: https://10.10.0.4/AcuPedia/acupedia-store-ui/pulls/70
Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
Amit Salunke 2026-10-27 04:50:43 +00:00
commit 8dc9d871d9
3 changed files with 7 additions and 7 deletions

View File

@ -148,7 +148,7 @@ export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
<input
type="tel"
value={profilePhone}
onChange={(e) => 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"

View File

@ -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',
}

View File

@ -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.';