Merge pull request 'bug(issue-82):fixed country wise mobile number length issue' (#95) from fix/phone-validation-7-to-15-digits into main

Reviewed-on: https://git.zedobject.local/AcuPedia/acupedia-mobile-ui/pulls/95
Reviewed-by: Amit Salunke <amit@noreply.localhost>
This commit is contained in:
Amit Salunke 2026-10-30 05:29:35 +00:00
commit 08e954bba0
2 changed files with 25 additions and 8 deletions

View File

@ -216,6 +216,7 @@ export const isValidPhoneNumber = (
return validatePhoneNumber(val, dialCode, country) === null; return validatePhoneNumber(val, dialCode, country) === null;
}; };
/** /**
* Updates the dial code prefix of an existing phone number when country changes. * Updates the dial code prefix of an existing phone number when country changes.
* Automatically clamps remaining digits to the new country's maxLength. * Automatically clamps remaining digits to the new country's maxLength.

View File

@ -65,7 +65,7 @@ export default function SignUpForm() {
const handlePhoneChange = (text: string) => { const handlePhoneChange = (text: string) => {
const digits = text.replace(/\D/g, ""); const digits = text.replace(/\D/g, "");
setPhone(digits.slice(0, 15)); setPhone(digits.slice(0, selectedCountry.maxLength));
if (phoneError) setPhoneError(""); if (phoneError) setPhoneError("");
}; };
@ -73,8 +73,8 @@ export default function SignUpForm() {
setSelectedCountry(c); setSelectedCountry(c);
setShowCountryModal(false); setShowCountryModal(false);
setCountrySearch(""); setCountrySearch("");
if (phone.length > 15) { if (phone.length > c.maxLength) {
setPhone(phone.slice(0, 15)); setPhone(phone.slice(0, c.maxLength));
} }
if (phoneError) setPhoneError(""); if (phoneError) setPhoneError("");
}; };
@ -101,9 +101,13 @@ export default function SignUpForm() {
} }
if (phone.trim()) { if (phone.trim()) {
const digits = phone.trim().replace(/\D/g, ""); const err = validatePhoneNumber(
if (digits.length < 7 || digits.length > 15) { phone.trim(),
setPhoneError("Phone number must be between 7 and 15 digits"); selectedCountry.code,
selectedCountry.country
);
if (err) {
setPhoneError(err);
hasError = true; hasError = true;
} }
} }
@ -231,13 +235,19 @@ export default function SignUpForm() {
autoCapitalize="none" autoCapitalize="none"
autoCorrect={false} autoCorrect={false}
textContentType="telephoneNumber" textContentType="telephoneNumber"
maxLength={15} maxLength={selectedCountry.maxLength}
style={styles.phoneInput} style={styles.phoneInput}
/> />
</View> </View>
{phoneError ? ( {phoneError ? (
<Text style={styles.errorText}>{phoneError}</Text> <Text style={styles.errorText}>{phoneError}</Text>
) : null} ) : (
<Text style={styles.phoneHelperText}>
{selectedCountry.minLength === selectedCountry.maxLength
? `${selectedCountry.country}: Requires exactly ${selectedCountry.maxLength} digits`
: `${selectedCountry.country}: ${selectedCountry.minLength} to ${selectedCountry.maxLength} digits`}
</Text>
)}
</View> </View>
<PasswordInput <PasswordInput
@ -437,6 +447,12 @@ const styles = StyleSheet.create({
marginTop: verticalScale(6), marginTop: verticalScale(6),
marginLeft: scale(6), marginLeft: scale(6),
}, },
phoneHelperText: {
color: AuthColors.textSecondary,
fontSize: moderateScale(11),
marginTop: verticalScale(4),
marginLeft: scale(6),
},
modalOverlay: { modalOverlay: {
flex: 1, flex: 1,