@@ -95,10 +95,10 @@ type Address struct {
95
95
96
96
func (a Address ) Validate () error {
97
97
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 )),
102
102
// State cannot be empty, and must be a string consisting of two letters in upper case
103
103
validation.Field (&a.State , validation.Required , validation.Match (regexp.MustCompile (" ^[A-Z]{2}$" ))),
104
104
// State cannot be empty, and must be a string consisting of five digits
@@ -153,10 +153,10 @@ err := validation.Validate(c,
153
153
validation.Key (" Email" , validation.Required , is.Email ),
154
154
// Validate Address using its own validation rules
155
155
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 )),
160
160
// State cannot be empty, and must be a string consisting of two letters in upper case
161
161
validation.Key (" State" , validation.Required , validation.Match (regexp.MustCompile (" ^[A-Z]{2}$" ))),
162
162
// State cannot be empty, and must be a string consisting of five digits
@@ -451,8 +451,8 @@ The following code implements the aforementioned examples:
451
451
``` go
452
452
result := validation.ValidateStruct (&a,
453
453
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." )),
456
456
)
457
457
```
458
458
@@ -463,8 +463,8 @@ The above code can also be simplified using the shortcut `validation.Required.Wh
463
463
``` go
464
464
result := validation.ValidateStruct (&a,
465
465
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." )),
468
468
)
469
469
```
470
470
@@ -659,6 +659,7 @@ Below is the whole list of the rules provided by the `is` package:
659
659
- ` UUIDv4 ` : validates if a string is a valid version 4 UUID
660
660
- ` UUIDv5 ` : validates if a string is a valid version 5 UUID
661
661
- ` UUID ` : validates if a string is a valid UUID
662
+ - ` ULID ` : validates if a string is a valid ULID
662
663
- ` CreditCard ` : validates if a string is a valid credit card number
663
664
- ` ISBN10 ` : validates if a string is an ISBN version 10
664
665
- ` ISBN13 ` : validates if a string is an ISBN version 13
0 commit comments