bug(issue-82):fixed country wise mobile number length issue #95
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue