Fixed phone validation for andriod
This commit is contained in:
@@ -103,7 +103,7 @@ public class PetAdapter extends RecyclerView.Adapter<PetAdapter.PetViewHolder> i
|
|||||||
|
|
||||||
binding.tvPetStatus.setText(pet.getPetStatus());
|
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) {
|
if (pet.getPetStatus() != null) {
|
||||||
switch (pet.getPetStatus()) {
|
switch (pet.getPetStatus()) {
|
||||||
case "Available":
|
case "Available":
|
||||||
|
|||||||
@@ -100,12 +100,13 @@ public class InputValidator {
|
|||||||
return true;
|
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) {
|
public static boolean isValidPhone(EditText field) {
|
||||||
String phone = field.getText().toString().trim();
|
String phone = field.getText().toString().trim();
|
||||||
// Android built in phone validation pattern
|
// Matches (XXX) XXX-XXXX format
|
||||||
if (phone.isEmpty() || !android.util.Patterns.PHONE.matcher(phone).matches()) {
|
String pattern = "^\\(\\d{3}\\) \\d{3}-\\d{4}$";
|
||||||
field.setError("Enter a valid phone number");
|
if (phone.isEmpty() || !phone.matches(pattern)) {
|
||||||
|
field.setError("Enter a valid phone number: (XXX) XXX-XXXX");
|
||||||
field.requestFocus();
|
field.requestFocus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user