Fixed phone validation for andriod

This commit is contained in:
Alex
2026-04-13 17:18:46 -06:00
parent 688a04c3bc
commit cba39e8a3c
2 changed files with 6 additions and 5 deletions

View File

@@ -103,7 +103,7 @@ public class PetAdapter extends RecyclerView.Adapter<PetAdapter.PetViewHolder> i
binding.tvPetStatus.setText(pet.getPetStatus());
//Set the status color depending on availability. If available, green, otherwise red
//Set the status color depending on availability. If available, green, If Pending, yellow, otherwise red
if (pet.getPetStatus() != null) {
switch (pet.getPetStatus()) {
case "Available":

View File

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