From 073390e6c087b7fdbae634bcdf8b4095b84159dd Mon Sep 17 00:00:00 2001 From: Tuan Nguyen <93944834+tuan-nxcr@users.noreply.github.com> Date: Wed, 14 Sep 2022 17:24:18 -0500 Subject: [PATCH] Update examples to reflect real US cities Proposal: Update example to validate City length between 1-50. Reasoning: For lazy developers like me, I started using this package by copying the examples for the addresses because I figured that they were grounded in real-world, common validation rules. I did tweak the State and Zipcode validation to be more general, but then we hit a snag when we realized that Novi, MI (4 characters) is a real US city. This led me to look into the real boundaries and I've landed on this PR as an enhancement to save headaches for other future lazy developers. :) Source: https://www.serviceobjects.com/blog/character-limits-in-address-lines-for-usps-ups-and-fedex/ (no minimum, so I assume 1, maximum 50) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6c14bbf..c8f3b0e 100644 --- a/README.md +++ b/README.md @@ -93,8 +93,8 @@ func (a Address) Validate() error { return validation.ValidateStruct(&a, // Street cannot be empty, and the length must between 5 and 50 validation.Field(&a.Street, validation.Required, validation.Length(5, 50)), - // City cannot be empty, and the length must between 5 and 50 - validation.Field(&a.City, validation.Required, validation.Length(5, 50)), + // City cannot be empty, and the length must between 1 and 50 + validation.Field(&a.City, validation.Required, validation.Length(1, 50)), // State cannot be empty, and must be a string consisting of two letters in upper case validation.Field(&a.State, validation.Required, validation.Match(regexp.MustCompile("^[A-Z]{2}$"))), // State cannot be empty, and must be a string consisting of five digits @@ -152,8 +152,8 @@ err := validation.Validate(c, validation.Key("Address", validation.Map( // Street cannot be empty, and the length must between 5 and 50 validation.Key("Street", validation.Required, validation.Length(5, 50)), - // City cannot be empty, and the length must between 5 and 50 - validation.Key("City", validation.Required, validation.Length(5, 50)), + // City cannot be empty, and the length must between 1 and 50 + validation.Key("City", validation.Required, validation.Length(1, 50)), // State cannot be empty, and must be a string consisting of two letters in upper case validation.Key("State", validation.Required, validation.Match(regexp.MustCompile("^[A-Z]{2}$"))), // State cannot be empty, and must be a string consisting of five digits