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;
};
/**
* Updates the dial code prefix of an existing phone number when country changes.
* 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 digits = text.replace(/\D/g, "");
setPhone(digits.slice(0, 15));
setPhone(digits.slice(0, selectedCountry.maxLength));
if (phoneError) setPhoneError("");
};
@ -73,8 +73,8 @@ export default function SignUpForm() {
setSelectedCountry(c);
setShowCountryModal(false);
setCountrySearch("");
if (phone.length > 15) {
setPhone(phone.slice(0, 15));
if (phone.length > c.maxLength) {
setPhone(phone.slice(0, c.maxLength));
}
if (phoneError) setPhoneError("");
};
@ -101,9 +101,13 @@ export default function SignUpForm() {
}
if (phone.trim()) {
const digits = phone.trim().replace(/\D/g, "");
if (digits.length < 7 || digits.length > 15) {
setPhoneError("Phone number must be between 7 and 15 digits");
const err = validatePhoneNumber(
phone.trim(),
selectedCountry.code,
selectedCountry.country
);
if (err) {
setPhoneError(err);
hasError = true;
}
}
@ -231,13 +235,19 @@ export default function SignUpForm() {
autoCapitalize="none"
autoCorrect={false}
textContentType="telephoneNumber"
maxLength={15}
maxLength={selectedCountry.maxLength}
style={styles.phoneInput}
/>
</View>
{phoneError ? (
<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>
<PasswordInput
@ -437,6 +447,12 @@ const styles = StyleSheet.create({
marginTop: verticalScale(6),
marginLeft: scale(6),
},
phoneHelperText: {
color: AuthColors.textSecondary,
fontSize: moderateScale(11),
marginTop: verticalScale(4),
marginLeft: scale(6),
},
modalOverlay: {
flex: 1,