Skip to content

Commit 0a60e1f

Browse files
authored
Merge pull request #2 from invopop/typos
Typos & Adding ULID
2 parents b0498eb + fc4e5e8 commit 0a60e1f

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ type Address struct {
9595

9696
func (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
452452
result := 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
464464
result := 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

is/rules.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ var (
5858
ErrUUIDv5 = validation.NewError("validation_is_uuid_v5", "must be a valid UUID v5")
5959
// ErrUUID is the error that returns in case of an invalid UUID value.
6060
ErrUUID = validation.NewError("validation_is_uuid", "must be a valid UUID")
61+
// ErrULID is the error that returns in case of an invalid ULID value.
62+
ErrULID = validation.NewError("validation_is_ulid", "must be a valid ULID")
6163
// ErrCreditCard is the error that returns in case of an invalid credit card number.
6264
ErrCreditCard = validation.NewError("validation_is_credit_card", "must be a valid credit card number")
6365
// ErrISBN10 is the error that returns in case of an invalid ISBN-10 value.
@@ -84,7 +86,7 @@ var (
8486
ErrBase64 = validation.NewError("validation_is_base64", "must be encoded in Base64")
8587
// ErrDataURI is the error that returns in case of an invalid data URI.
8688
ErrDataURI = validation.NewError("validation_is_data_uri", "must be a Base64-encoded data URI")
87-
// ErrE164 is the error that returns in case of an invalid e165.
89+
// ErrE164 is the error that returns in case of an invalid e164.
8890
ErrE164 = validation.NewError("validation_is_e164_number", "must be a valid E164 number")
8991
// ErrCountryCode2 is the error that returns in case of an invalid two-letter country code.
9092
ErrCountryCode2 = validation.NewError("validation_is_country_code_2_letter", "must be a valid two-letter country code")
@@ -197,7 +199,7 @@ var (
197199
Base64 = validation.NewStringRuleWithError(govalidator.IsBase64, ErrBase64)
198200
// DataURI validates if a string is a valid base64-encoded data URI
199201
DataURI = validation.NewStringRuleWithError(govalidator.IsDataURI, ErrDataURI)
200-
// E164 validates if a string is a valid ISO3166 Alpha 2 country code
202+
// E164 validates if a string is a valid E164 telephone number
201203
E164 = validation.NewStringRuleWithError(isE164Number, ErrE164)
202204
// CountryCode2 validates if a string is a valid ISO3166 Alpha 2 country code
203205
CountryCode2 = validation.NewStringRuleWithError(govalidator.IsISO3166Alpha2, ErrCountryCode2)

0 commit comments

Comments
 (0)