issue(60): enforce 7-15 digits and 15 digit input limit on phone numbers #84
|
|
@ -41,7 +41,8 @@ export default function LoginForm({
|
|||
|
||||
const handlePhoneChange = (text: string) => {
|
||||
const digits = text.replace(/\D/g, "");
|
||||
setPhone(digits.slice(0, 10));
|
||||
setPhone(digits.slice(0, 15));
|
||||
if (phoneError) setPhoneError("");
|
||||
};
|
||||
|
||||
const handleLogin = async () => {
|
||||
|
|
@ -62,8 +63,8 @@ export default function LoginForm({
|
|||
if (!phone.trim()) {
|
||||
setPhoneError("Phone number is required");
|
||||
hasError = true;
|
||||
} else if (phone.length < 10) {
|
||||
setPhoneError("Phone number must be 10 digits");
|
||||
} else if (phone.length < 7 || phone.length > 15) {
|
||||
setPhoneError("Phone number must be between 7 and 15 digits");
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -130,7 +131,7 @@ export default function LoginForm({
|
|||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
textContentType="telephoneNumber"
|
||||
maxLength={10}
|
||||
maxLength={15}
|
||||
leftIcon="call-outline"
|
||||
error={phoneError}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ export default function SignUpForm() {
|
|||
|
||||
const handlePhoneChange = (text: string) => {
|
||||
const digits = text.replace(/\D/g, "");
|
||||
setPhone(digits.slice(0, selectedCountry.maxLength));
|
||||
setPhone(digits.slice(0, 15));
|
||||
if (phoneError) setPhoneError("");
|
||||
};
|
||||
|
||||
|
|
@ -73,8 +73,8 @@ export default function SignUpForm() {
|
|||
setSelectedCountry(c);
|
||||
setShowCountryModal(false);
|
||||
setCountrySearch("");
|
||||
if (phone.length > c.maxLength) {
|
||||
setPhone(phone.slice(0, c.maxLength));
|
||||
if (phone.length > 15) {
|
||||
setPhone(phone.slice(0, 15));
|
||||
}
|
||||
if (phoneError) setPhoneError("");
|
||||
};
|
||||
|
|
@ -101,13 +101,9 @@ export default function SignUpForm() {
|
|||
}
|
||||
|
||||
if (phone.trim()) {
|
||||
const err = validatePhoneNumber(
|
||||
phone,
|
||||
selectedCountry.code,
|
||||
selectedCountry.country
|
||||
);
|
||||
if (err) {
|
||||
setPhoneError(err);
|
||||
const digits = phone.trim().replace(/\D/g, "");
|
||||
if (digits.length < 7 || digits.length > 15) {
|
||||
setPhoneError("Phone number must be between 7 and 15 digits");
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -235,7 +231,7 @@ export default function SignUpForm() {
|
|||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
textContentType="telephoneNumber"
|
||||
maxLength={selectedCountry.maxLength}
|
||||
maxLength={15}
|
||||
style={styles.phoneInput}
|
||||
/>
|
||||
</View>
|
||||
|
|
|
|||
|
|
@ -57,8 +57,8 @@ export const isValidPhoneNumber = (val?: string): boolean => {
|
|||
return false;
|
||||
}
|
||||
const digits = trimmed.replace(/\D/g, "");
|
||||
// ITU-T E.164 standard allows 6 to 15 digits
|
||||
return digits.length >= 6 && digits.length <= 15;
|
||||
// ITU-T E.164 standard: minimum 7 and maximum 15 digits
|
||||
return digits.length >= 7 && digits.length <= 15;
|
||||
};
|
||||
|
||||
const cleanPhoneInput = (text: string): string => {
|
||||
|
|
@ -66,7 +66,19 @@ const cleanPhoneInput = (text: string): string => {
|
|||
const hasPlus = trimmedStart.startsWith("+");
|
||||
const rest = hasPlus ? trimmedStart.slice(1) : text;
|
||||
const filtered = rest.replace(/[^0-9\s\-()]/g, "");
|
||||
return hasPlus ? `+${filtered}` : filtered;
|
||||
let digitCount = 0;
|
||||
let bounded = "";
|
||||
for (const ch of filtered) {
|
||||
if (/\d/.test(ch)) {
|
||||
if (digitCount < 15) {
|
||||
digitCount++;
|
||||
bounded += ch;
|
||||
}
|
||||
} else {
|
||||
bounded += ch;
|
||||
}
|
||||
}
|
||||
return hasPlus ? `+${bounded}` : bounded;
|
||||
};
|
||||
|
||||
export default function EditProfileForm({
|
||||
|
|
@ -126,7 +138,7 @@ export default function EditProfileForm({
|
|||
|
||||
const trimmedPhone = phone.trim();
|
||||
if (trimmedPhone && !isValidPhoneNumber(trimmedPhone)) {
|
||||
setPhoneError("Please enter a valid phone number");
|
||||
setPhoneError("Phone number must be between 7 and 15 digits");
|
||||
hasError = true;
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +183,7 @@ export default function EditProfileForm({
|
|||
onChangeText={handlePhoneChange}
|
||||
placeholder="e.g. +91 9876543210"
|
||||
keyboardType="phone-pad"
|
||||
maxLength={25}
|
||||
maxLength={16}
|
||||
textContentType="telephoneNumber"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export default function EditProfileScreen() {
|
|||
const trimmedCountry = updatedCountry.trim();
|
||||
|
||||
if (trimmedPhone && !isValidPhoneNumber(trimmedPhone)) {
|
||||
const errMsg = "Please enter a valid phone number";
|
||||
const errMsg = "Phone number must be between 7 and 15 digits";
|
||||
if (Platform.OS === "web") {
|
||||
window.alert(errMsg);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue