Changed android phone validation

This commit is contained in:
Alex
2026-04-14 22:53:42 -06:00
parent 9c47f5ac76
commit 7340a5616e

View File

@@ -100,13 +100,12 @@ public class InputValidator {
return true;
}
// Checks if the phone number is valid in (XXX) XXX-XXXX format
// Checks if the phone number is valid: XXX-XXX-XXXX, (XXX) XXX-XXXX, or XXXXXXXXXX
public static boolean isValidPhone(EditText field) {
String phone = field.getText().toString().trim();
// Matches (XXX) XXX-XXXX format
String pattern = "^\\(\\d{3}\\) \\d{3}-\\d{4}$";
String pattern = "^(\\(\\d{3}\\) \\d{3}-\\d{4}|\\d{3}-\\d{3}-\\d{4}|\\d{10})$";
if (phone.isEmpty() || !phone.matches(pattern)) {
field.setError("Enter a valid phone number: (XXX) XXX-XXXX");
field.setError("Enter a valid phone number");
field.requestFocus();
return false;
}