@@ -95,10 +95,10 @@ type Address struct {
9595
9696func (a Address ) Validate () error {
9797 return validation.ValidateStruct (&a,
98- // Street cannot be empty, and the length must between 5 and 50
99- validation.Field (&a.Street , validation.Required , validation.Length (5 , 50 )),
100- // City cannot be empty, and the length must between 5 and 50
101- validation.Field (&a.City , validation.Required , validation.Length (5 , 50 )),
98+ // Street cannot be empty, and the length must between 2 and 50
99+ validation.Field (&a.Street , validation.Required , validation.Length (2 , 50 )),
100+ // City cannot be empty, and the length must between 2 and 50
101+ validation.Field (&a.City , validation.Required , validation.Length (2 , 50 )),
102102 // State cannot be empty, and must be a string consisting of two letters in upper case
103103 validation.Field (&a.State , validation.Required , validation.Match (regexp.MustCompile (" ^[A-Z]{2}$" ))),
104104 // State cannot be empty, and must be a string consisting of five digits
@@ -153,10 +153,10 @@ err := validation.Validate(c,
153153 validation.Key (" Email" , validation.Required , is.Email ),
154154 // Validate Address using its own validation rules
155155 validation.Key (" Address" , validation.Map (
156- // Street cannot be empty, and the length must between 5 and 50
157- validation.Key (" Street" , validation.Required , validation.Length (5 , 50 )),
158- // City cannot be empty, and the length must between 5 and 50
159- validation.Key (" City" , validation.Required , validation.Length (5 , 50 )),
156+ // Street cannot be empty, and the length must between 2 and 50
157+ validation.Key (" Street" , validation.Required , validation.Length (2 , 50 )),
158+ // City cannot be empty, and the length must between 2 and 50
159+ validation.Key (" City" , validation.Required , validation.Length (2 , 50 )),
160160 // State cannot be empty, and must be a string consisting of two letters in upper case
161161 validation.Key (" State" , validation.Required , validation.Match (regexp.MustCompile (" ^[A-Z]{2}$" ))),
162162 // State cannot be empty, and must be a string consisting of five digits
@@ -451,8 +451,8 @@ The following code implements the aforementioned examples:
451451``` go
452452result := validation.ValidateStruct (&a,
453453 validation.Field (&a.Unit , validation.When (a.Quantity != " " , validation.Required ).Else (validation.Nil )),
454- validation.Field (&a.Phone , validation.When (a.Email == " " , validation.Required .Error (' Either phone or Email is required.' )),
455- validation.Field (&a.Email , validation.When (a.Phone == " " , validation.Required .Error (' Either phone or Email is required.' )),
454+ validation.Field (&a.Phone , validation.When (a.Email == " " , validation.Required .Error (" Either phone or Email is required." )),
455+ validation.Field (&a.Email , validation.When (a.Phone == " " , validation.Required .Error (" Either phone or Email is required." )),
456456)
457457```
458458
@@ -463,8 +463,8 @@ The above code can also be simplified using the shortcut `validation.Required.Wh
463463``` go
464464result := validation.ValidateStruct (&a,
465465 validation.Field (&a.Unit , validation.Required .When (a.Quantity != " " ), validation.Nil .When (a.Quantity == " " )),
466- validation.Field (&a.Phone , validation.Required .When (a.Email == " " ).Error (' Either phone or Email is required.' )),
467- validation.Field (&a.Email , validation.Required .When (a.Phone == " " ).Error (' Either phone or Email is required.' )),
466+ validation.Field (&a.Phone , validation.Required .When (a.Email == " " ).Error (" Either phone or Email is required." )),
467+ validation.Field (&a.Email , validation.Required .When (a.Phone == " " ).Error (" Either phone or Email is required." )),
468468)
469469```
470470
@@ -659,6 +659,7 @@ Below is the whole list of the rules provided by the `is` package:
659659- ` UUIDv4 ` : validates if a string is a valid version 4 UUID
660660- ` UUIDv5 ` : validates if a string is a valid version 5 UUID
661661- ` UUID ` : validates if a string is a valid UUID
662+ - ` ULID ` : validates if a string is a valid ULID
662663- ` CreditCard ` : validates if a string is a valid credit card number
663664- ` ISBN10 ` : validates if a string is an ISBN version 10
664665- ` ISBN13 ` : validates if a string is an ISBN version 13
0 commit comments