diff --git a/src/main/java/com/graqr/threshr/model/queryparam/Place.java b/src/main/java/com/graqr/threshr/model/queryparam/Place.java index 9ee3266..f797dba 100644 --- a/src/main/java/com/graqr/threshr/model/queryparam/Place.java +++ b/src/main/java/com/graqr/threshr/model/queryparam/Place.java @@ -3,6 +3,10 @@ import io.micronaut.serde.annotation.Serdeable; import lombok.Data; +/** + * Place is a query parameter used when querying nearby target store locations. The query accepts either a zipcode + * or a city-state combo. See {@link com.graqr.threshr.Threshr#queryStoreLocations(Place)}. + */ @Serdeable @Data public class Place { @@ -17,15 +21,15 @@ public Place(String zipcode) { public Place(String city, String state) { String errorMessage = ""; - if (!String.valueOf(city).matches("^([a-zA-Z\\u0080-\\u024F]+(?:. |-| |'))*[a-zA-Z\\u0080-\\u024F]*$")) { - errorMessage = "Invalid city string provided, \"" + city + "\". String provided " + - "must match this regex: \"^([a-zA-Z\\u0080-\\u024F]+(?:. |-| |'))*[a-zA-Z\\u0080-\\u024F]*$\"."; + //match weird strings like D'Amoreport (texas) and Coeur D'Alene (idaho) + String pattern = "^([a-zA-Z|\\u0080-\\u024F]\\W?)*+$"; // *+ quantifier prevents backtracking + if (!String.valueOf(city).matches(pattern)) { + errorMessage = "Invalid city string provided, \"" + city + "\"."; } else if (city.isEmpty()) { errorMessage = "String value for city cannot be empty."; } - if (!String.valueOf(state).matches("^[A-Z][a-z]+(?: +[A-Z][a-z]+)*$")) { - errorMessage = "Invalid state string provided, \"" + state + "\". String provided " + - "must match this regex: \"^[A-Z][a-z]+(?: +[A-Z][a-z]+)*$\"."; + if (!String.valueOf(state).matches(pattern)) { + errorMessage = "Invalid state string provided, \"" + state + "\"."; } else if (state.isEmpty()) { errorMessage += "String value for state cannot be empty."; }