diff --git a/backend/src/main/java/ca/bc/gov/app/validator/address/AddressAddressValidator.java b/backend/src/main/java/ca/bc/gov/app/validator/address/AddressAddressValidator.java index f903fa7623..3ed866f802 100644 --- a/backend/src/main/java/ca/bc/gov/app/validator/address/AddressAddressValidator.java +++ b/backend/src/main/java/ca/bc/gov/app/validator/address/AddressAddressValidator.java @@ -31,13 +31,20 @@ public Mono validate(ClientAddressDto target, Integer index) { return Mono.just( new ValidationError(fieldName, "You must enter a street address or PO box number.")); } + if (!US7ASCII_PATTERN.matcher(fieldValue).matches()) { return Mono.just(new ValidationError(fieldName, String.format("%s has an invalid character.", fieldValue))); } + + if (StringUtils.length(fieldValue) < 4) { + return Mono.just(new ValidationError(fieldName, "The address must be between 4 and 40 characters.")); + } + if (StringUtils.length(fieldValue) > 40) { - return Mono.just(new ValidationError(fieldName, "This field has a 40 character limit.")); + return Mono.just(new ValidationError(fieldName, "The address must be between 4 and 40 characters.")); } + return Mono.empty(); } } diff --git a/backend/src/main/java/ca/bc/gov/app/validator/address/AddressComplementaryInformationValidator.java b/backend/src/main/java/ca/bc/gov/app/validator/address/AddressComplementaryInformationValidator.java index 21dd3991b9..7c232dda2e 100644 --- a/backend/src/main/java/ca/bc/gov/app/validator/address/AddressComplementaryInformationValidator.java +++ b/backend/src/main/java/ca/bc/gov/app/validator/address/AddressComplementaryInformationValidator.java @@ -51,8 +51,13 @@ private Mono validateAddressField(String content, String fieldN return Mono.just( new ValidationError(fieldName, String.format("%s has an invalid character.", content))); } + + if (StringUtils.length(content) < 4) { + return Mono.just(new ValidationError(fieldName, "The address must be between 4 and 40 characters.")); + } + if (StringUtils.length(content) > 40) { - return Mono.just(new ValidationError(fieldName, "This field has a 40 character limit.")); + return Mono.just(new ValidationError(fieldName, "The address must be between 4 and 40 characters.")); } } return Mono.empty(); diff --git a/backend/src/main/java/ca/bc/gov/app/validator/address/AddressNameValidator.java b/backend/src/main/java/ca/bc/gov/app/validator/address/AddressNameValidator.java index 0f4b8e3b91..e70d2b64d8 100644 --- a/backend/src/main/java/ca/bc/gov/app/validator/address/AddressNameValidator.java +++ b/backend/src/main/java/ca/bc/gov/app/validator/address/AddressNameValidator.java @@ -40,6 +40,7 @@ public Mono validate(ClientAddressDto target, Integer index) { if (StringUtils.length(target.locationName()) > 40) { return Mono.just(new ValidationError(fieldName, "This field has a 40 character limit.")); } + return Mono.empty(); } } diff --git a/backend/src/test/java/ca/bc/gov/app/validator/address/AddressAddressValidatorTest.java b/backend/src/test/java/ca/bc/gov/app/validator/address/AddressAddressValidatorTest.java index ba50299db8..829a747ade 100644 --- a/backend/src/test/java/ca/bc/gov/app/validator/address/AddressAddressValidatorTest.java +++ b/backend/src/test/java/ca/bc/gov/app/validator/address/AddressAddressValidatorTest.java @@ -88,14 +88,12 @@ public static Stream validSources() { } private static Stream validation() { - return - Stream.of( - Arguments.of(StringUtils.EMPTY, "You must enter a street address or PO box number."), - Arguments.of("1234 Mainé St", "1234 Mainé St has an invalid character."), - Arguments.of("Avenida Bailarina Selma Parada 505, Sala 12 Conjunto 5", - "This field has a 40 character limit."), - Arguments.of("1234 Main St", StringUtils.EMPTY) - ); + return Stream.of( + Arguments.of(StringUtils.EMPTY, "You must enter a street address or PO box number."), + Arguments.of("1234 Mainé St", "1234 Mainé St has an invalid character."), + Arguments.of("Avenida Bailarina Selma Parada 505, Sala 12 Conjunto 5", + "The address must be between 4 and 40 characters."), + Arguments.of("1234 Main St", StringUtils.EMPTY)); } } \ No newline at end of file diff --git a/backend/src/test/java/ca/bc/gov/app/validator/address/AddressComplementaryInformationValidatorTest.java b/backend/src/test/java/ca/bc/gov/app/validator/address/AddressComplementaryInformationValidatorTest.java index 64d5aef5f6..eac2a0d657 100644 --- a/backend/src/test/java/ca/bc/gov/app/validator/address/AddressComplementaryInformationValidatorTest.java +++ b/backend/src/test/java/ca/bc/gov/app/validator/address/AddressComplementaryInformationValidatorTest.java @@ -69,20 +69,31 @@ void shouldValidate( } private static Stream validation() { - return - Stream.of( - Arguments.of(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, - StringUtils.EMPTY), - Arguments.of(StringUtils.EMPTY, "Something", "One", - "You must enter the first complementary address."), - Arguments.of("Something é", StringUtils.EMPTY, "One", - "Something é has an invalid character."), - Arguments.of("Potato".repeat(10), StringUtils.EMPTY, "One", - "This field has a 40 character limit."), - Arguments.of("Potato", "Something é", "Two", "Something é has an invalid character."), - Arguments.of("Potato", "Potato".repeat(10), "Two", - "This field has a 40 character limit.") - ); + return Stream.of( + Arguments.of(StringUtils.EMPTY, + StringUtils.EMPTY, + StringUtils.EMPTY, + StringUtils.EMPTY), + Arguments.of(StringUtils.EMPTY, + "Something", + "One", + "You must enter the first complementary address."), + Arguments.of("Something é", + StringUtils.EMPTY, + "One", + "Something é has an invalid character."), + Arguments.of("Potato".repeat(10), + StringUtils.EMPTY, + "One", + "The address must be between 4 and 40 characters."), + Arguments.of("Potato", + "Something é", + "Two", + "Something é has an invalid character."), + Arguments.of("Potato", + "Potato".repeat(10), + "Two", + "The address must be between 4 and 40 characters.")); } } \ No newline at end of file diff --git a/frontend/src/helpers/validators/BCeIDFormValidations.ts b/frontend/src/helpers/validators/BCeIDFormValidations.ts index a19740a955..5652fdeec2 100644 --- a/frontend/src/helpers/validators/BCeIDFormValidations.ts +++ b/frontend/src/helpers/validators/BCeIDFormValidations.ts @@ -67,8 +67,8 @@ formFieldValidations["location.addresses.*.city"] = [ ]; formFieldValidations["location.addresses.*.streetAddress"] = [ isNotEmpty("Please provide a valid address or PO Box"), - isMinSize("The address must be between 5 and 40 characters")(5), - isMaxSize("The address must be between 5 and 40 characters")(40), + isMinSize("The address must be between 4 and 40 characters")(4), + isMaxSize("The address must be between 4 and 40 characters")(40), isAscii("address"), ]; formFieldValidations[ @@ -129,4 +129,4 @@ export const addValidation = ( }; export const getValidations = (key: string): ((value: any) => string)[] => - key ? formFieldValidations[key] || [] : []; \ No newline at end of file + key ? formFieldValidations[key] || [] : []; diff --git a/frontend/src/helpers/validators/StaffFormValidations.ts b/frontend/src/helpers/validators/StaffFormValidations.ts index 2b7980ca84..14147cc17b 100644 --- a/frontend/src/helpers/validators/StaffFormValidations.ts +++ b/frontend/src/helpers/validators/StaffFormValidations.ts @@ -258,8 +258,8 @@ fieldValidations["location.addresses.*.city"] = [ ]; fieldValidations["location.addresses.*.streetAddress"] = [ isNotEmpty("Please provide a valid address or PO Box"), - isMinSize("The address must be between 5 and 40 characters")(5), - isMaxSize("The address must be between 5 and 40 characters")(40), + isMinSize("The address must be between 4 and 40 characters")(4), + isMaxSize("The address must be between 4 and 40 characters")(40), isAscii("address"), ]; fieldValidations[ @@ -337,4 +337,4 @@ export const validate = ( return globalValidate.apply(this, args); }; -export const runValidation = globalRunValidation; \ No newline at end of file +export const runValidation = globalRunValidation;