issue(60): enforce 7-15 digits and 15 digit input limit on phone numbers
This commit is contained in:
parent
98efd5899d
commit
aebcdccc8a
|
|
@ -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}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ export default function SignUpForm() {
|
|||
|
||||
const handlePhoneChange = (text: string) => {
|
||||
const digits = text.replace(/\D/g, "");
|
||||
setPhone(digits.slice(0, 10));
|
||||
setPhone(digits.slice(0, 15));
|
||||
if (phoneError) setPhoneError("");
|
||||
};
|
||||
|
||||
const handleSignUp = async () => {
|
||||
|
|
@ -52,9 +53,12 @@ export default function SignUpForm() {
|
|||
hasError = true;
|
||||
}
|
||||
|
||||
if (phone.trim() && phone.length < 10) {
|
||||
setPhoneError("Phone number must be 10 digits");
|
||||
hasError = true;
|
||||
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");
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!password) {
|
||||
|
|
@ -149,7 +153,7 @@ export default function SignUpForm() {
|
|||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
textContentType="telephoneNumber"
|
||||
maxLength={10}
|
||||
maxLength={15}
|
||||
leftIcon="call-outline"
|
||||
error={phoneError}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -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