diff --git a/README.md b/README.md index a5b9bdb..afd2797 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ and a conversion that doesn't fit the field doesn't compile: | Conversion | Fields | Rules | |---|---|---| -| `str.Of` | `string`, `*string`, named strings | `Required`, lengths in bytes and runes, `AnyOf`, `Prefix`, `Suffix`, `Contains`, `Regexp`, `Email`, `URL`, `IP`, `CIDR`, `MAC`, `Hostname`, `UUID`, `E164`, `Base64`, `JSON`, `Semver`, `HexColor`, `Datetime`, `CountryCode`, `CurrencyCode`, `CreditCard`, `Trim`... | -| `num.Of`, `num.Ptr` | integers, floats, named numbers, pointers to them | `Required`, `Min`, `Max`, `AnyOf`, `AnyOfInterval`, `Latitude`, `Longitude` | +| `str.Of` | `string`, `*string`, named strings | `Required`, lengths in bytes and runes, `AnyOf`, `Prefix`, `Suffix`, `Contains`, `Excludes`, `Alpha`, `Digits`, `Numeric`, `Hexadecimal`, `Regexp`, `Email`, `URL`, `IP`, `CIDR`, `MAC`, `Hostname`, `UUID`, `E164`, `Base64`, `JSON`, `Semver`, `HexColor`, `Datetime`, `CountryCode`, `CurrencyCode`, `CreditCard`, `Trim`... | +| `num.Of`, `num.Ptr` | integers, floats, named numbers, pointers to them | `Required`, `Min`, `Max`, `GreaterThan`, `LessThan`, `AnyOf`, `AnyOfInterval`, `Latitude`, `Longitude` | | `timex.Of` | `time.Time`, `*time.Time` | `Required`, `Before`, `After`, `Between`, `InPast`, `InFuture` | | `eq.Of`, `eq.Ptr` | any `comparable`: enums, bools | `Required`, `OneOf`, `NotOneOf`, `Equal`, `NotEqual` | | `vuuid.Of` | `uuid.UUID`, `*uuid.UUID`, the separate module `github.com/insei/valigo/rules/uuid` | `Required`, `AnyOf` | diff --git a/docs/features/errors.md b/docs/features/errors.md index c3553b4..a6a6332 100644 --- a/docs/features/errors.md +++ b/docs/features/errors.md @@ -83,12 +83,17 @@ Output: | `string.max_len`, `string.max_runes` | `max` | | `string.any_of` | `values` | | `string.prefix`, `string.suffix`, `string.contains` | `prefix`, `suffix`, `substring` | -| `string.equal_field` | `field` | +| `string.equal_field`, `string.not_equal_field` | `field` | +| `string.excludes`, `string.not_prefix`, `string.not_suffix` | `substring`, `prefix`, `suffix` | +| `string.contains_any`, `string.excludes_any` | `chars` | +| `string.equal_fold` | `value` | +| `string.alpha`, `string.digits`, `string.numeric`, `string.hexadecimal` | — | | `string.base64`, `string.base64url`, `string.json`, `string.semver`, `string.cidr`, `string.mac`, `string.e164`, `string.hex_color`, `string.ascii`, `string.lowercase`, `string.uppercase`, `string.country_code`, `string.currency_code`, `string.luhn`, `string.credit_card` | — | | `string.datetime` | `layout` | | `number.required` | — | | `number.min`, `number.max` | `min`, `max` | -| `number.min_field`, `number.max_field` | `field` | +| `number.min_field`, `number.max_field`, `number.greater_field`, `number.less_field` | `field` | +| `number.greater_than`, `number.less_than` | `min`, `max` | | `number.any_of` | `values` | | `number.interval` | `min`, `max` | | `number.latitude`, `number.longitude` | — | @@ -99,7 +104,7 @@ Output: | `value.required`, `value.unique` | — | | `value.one_of`, `value.not_one_of` | `values` | | `value.equal`, `value.not_equal` | `value` | -| `value.equal_field` | `field` | +| `value.equal_field`, `value.not_equal_field` | `field` | | `uuid.required` | — | | `uuid.any_of` | `values` | | `slice.required`, `map.required` | — | diff --git a/docs/features/numbers.md b/docs/features/numbers.md index 63233c7..2b4dab5 100644 --- a/docs/features/numbers.md +++ b/docs/features/numbers.md @@ -33,6 +33,8 @@ Slices of numbers are converted by `num.Slice`: `b.Slice(&p.Sizes).As(num.Slice) | `Required()` | `num.Of`: the value is zero; `num.Ptr`: the value is absent | Should be fulfilled | | `Min(n)` | the value is less than `n` | Cannot be less than %v | | `Max(n)` | the value is greater than `n` | Cannot be greater than %v | +| `GreaterThan(n)`, `LessThan(n)` | the value isn't greater / less than `n` | Should be greater than %v, Should be less than %v | +| `GreaterField(&m.X)`, `LessField(&m.X)` | the value isn't greater / less than the value of the field `X` | Should be greater than %v, Should be less than %v | | `MinField(&m.X)`, `MaxField(&m.X)` | the value is less or greater than the value of the field `X`, see [Rules on other fields](fields.md) | Cannot be less than %v, Cannot be greater than %v | | `AnyOf(values...)` | the value isn't one of `values` | Only %v values is allowed | | `AnyOfInterval(begin, end)` | the value is outside `[begin, end]`, both ends are included | Only interval[%v - %v] is allowed | diff --git a/docs/features/schema.md b/docs/features/schema.md index a973238..bb18722 100644 --- a/docs/features/schema.md +++ b/docs/features/schema.md @@ -14,13 +14,13 @@ Every `shared.Constraint` has the configured struct, the field, the path from th |---|---| | `str`: `Required` | `required`, `minLength: 1` | | `str`: `MinRunes`, `MaxRunes`, `MaxLen` | `minLength`, `maxLength` | -| `str`: `Regexp`, `Prefix`, `Suffix`, `Contains`, `Alphanumeric`, `Semver`, `E164`, `HexColor` | `pattern` | +| `str`: `Regexp`, `Prefix`, `Suffix`, `Contains`, `Alphanumeric`, `Alpha`, `Digits`, `Numeric`, `Hexadecimal`, `Semver`, `E164`, `HexColor` | `pattern` | | `str`: `Email`, `URL`, `IPv4`, `IPv6`, `Hostname`, `UUID` | `format`: `email`, `uri`, `ipv4`, `ipv6`, `hostname`, `uuid` | | `str`: `Datetime(time.RFC3339)`, `Datetime(time.DateOnly)` | `format`: `date-time`, `date` | | `str`: `Base64`, `Base64URL` | `contentEncoding` | | `str`, `num`, `uuid`: `AnyOf`; `eq`: `OneOf` | `enum` | | `eq`: `Equal` | `const` | -| `num`: `Min`, `Max`, `AnyOfInterval`, `Latitude`, `Longitude` | `minimum`, `maximum` | +| `num`: `Min`, `Max`, `AnyOfInterval`, `Latitude`, `Longitude`, `GreaterThan`, `LessThan` | `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum` | | `num`, `eq`, `uuid`: `Required` | `required` | | slices: `Required`, `MinLen`, `MaxLen`, `Unique`, `Each` | `required` and `minItems: 1`, `minItems`, `maxItems`, `uniqueItems`, `items` | | maps: `Required`, `MinLen`, `MaxLen`, `EachKey`, `EachValue` | `required` and `minProperties: 1`, `minProperties`, `maxProperties`, `propertyNames`, `additionalProperties` | diff --git a/docs/features/strings.md b/docs/features/strings.md index d494e16..942c687 100644 --- a/docs/features/strings.md +++ b/docs/features/strings.md @@ -33,7 +33,11 @@ b.Slice(&u.Emails).As(str.Slice).MaxLen(3).Email() | `MaxRunes(n)` | the number of characters (runes) is greater than `n` | Cannot be longer than %d characters | | `AnyOf(values...)` | the value isn't one of `values` | Only %s values is allowed | | `EqualField(&m.X)` | the value isn't equal to the value of the string field `X`, see [Rules on other fields](fields.md) | Should be equal to %s | +| `NotEqualField(&m.X)` | the value is equal to the value of the string field `X` | Cannot be equal to %s | +| `EqualFold(s)` | the value isn't equal to `s` ignoring case, by Unicode case folding | Should be equal to %s ignoring case | | `Prefix(s)`, `Suffix(s)`, `Contains(s)` | the value doesn't start with, end with or contain `s` | Should start with %s, Should end with %s, Should contain %s | +| `NotPrefix(s)`, `NotSuffix(s)`, `Excludes(s)` | the value starts with, ends with or contains `s` | Cannot start with %s, Cannot end with %s, Cannot contain %s | +| `ContainsAny(chars)`, `ExcludesAny(chars)` | the value has none / one of the characters of `chars` | Should contain any of the characters %s, Cannot contain the characters %s | | `Regexp(re, opts...)` | the value doesn't match `re` | Doesn't match required regexp pattern | | `Email()` | the value isn't an email address | Should be email address | | `URL()` | the value isn't an absolute URL with a scheme and a host | Should be URL | @@ -41,6 +45,10 @@ b.Slice(&u.Emails).As(str.Slice).MaxLen(3).Email() | `Hostname()` | the value isn't a hostname by RFC 1123 | Should be hostname | | `UUID()` | the value isn't a UUID in the canonical form, any case | Should be UUID | | `Alphanumeric()` | the value is empty or has characters other than ASCII letters and digits | Should contain only letters and digits | +| `Alpha()` | the value is empty or has characters other than ASCII letters | Should contain only letters | +| `Digits()` | the value is empty or has characters other than ASCII digits, `0042` | Should contain only digits | +| `Numeric()` | the value isn't a decimal number with an optional sign and fraction, `-12`, `+3.5` | Should be a number | +| `Hexadecimal()` | the value isn't a hexadecimal number with an optional `0x`, `ff`, `0x1A` | Should be hexadecimal | | `ASCII()` | the value is empty or has non-ASCII characters | Should contain only ASCII characters | | `Lowercase()`, `Uppercase()` | the value is empty or has upper / lower case letters | Should be lowercase, Should be uppercase | | `Base64()`, `Base64URL()` | the value isn't base64 of RFC 4648 with the standard alphabet and padding / with the URL alphabet, padding optional | Should be base64 encoded, Should be base64url encoded | diff --git a/docs/features/values.md b/docs/features/values.md index 78ae979..160731b 100644 --- a/docs/features/values.md +++ b/docs/features/values.md @@ -28,6 +28,7 @@ For strings and numbers [`str.Of`](strings.md) and [`num.Of`](numbers.md) have m | `Equal(v)` | the value isn't `v` | Should be %v | | `NotEqual(v)` | the value is `v` | Cannot be %v | | `EqualField(&m.X)` | the value isn't equal to the value of the field `X`, see [Rules on other fields](fields.md) | Should be equal to %s | +| `NotEqualField(&m.X)` | the value is equal to the value of the field `X` | Cannot be equal to %s | | `Custom(fn)` | `fn` returns errors | your messages, see [Custom rules](custom.md) | | `When(fn)` | — | the next rules are applied only if `fn` returns true, see [Conditions](conditions.md) | diff --git a/rules/eq/base.go b/rules/eq/base.go index 4ee23ad..dab957d 100644 --- a/rules/eq/base.go +++ b/rules/eq/base.go @@ -16,6 +16,7 @@ const ( equalLocaleKey = "validation:value:Should be %v" notEqualLocaleKey = "validation:value:Cannot be %v" equalFieldKey = "validation:value:Should be equal to %s" + notEqualFieldKey = "validation:value:Cannot be equal to %s" ) // BaseConfigurator configures rules for a comparable value. @@ -78,6 +79,13 @@ func (i *BaseConfigurator[T]) EqualField(other *T) *BaseConfigurator[T] { return i } +// NotEqualField checks if the value differs from the value of another field of the object: +// b.Field(&m.Target).As(eq.Of).NotEqualField(&m.Source). +func (i *BaseConfigurator[T]) NotEqualField(other *T) *BaseConfigurator[T] { + i.f.CheckWithMsg(other, func(v, o T) bool { return v != o }, shared.M("value.not_equal_field", notEqualFieldKey)) + return i +} + // NotEqual checks if the value is not equal to forbidden. func (i *BaseConfigurator[T]) NotEqual(forbidden T) *BaseConfigurator[T] { i.f.CheckMsg(func(v T) bool { return v != forbidden }, shared.M("value.not_equal", notEqualLocaleKey, shared.P("value", forbidden))) diff --git a/rules/eq/base_test.go b/rules/eq/base_test.go index 0357a38..7d8d0ee 100644 --- a/rules/eq/base_test.go +++ b/rules/eq/base_test.go @@ -138,12 +138,12 @@ func TestZeroAllocationsOnValid(t *testing.T) { func TestCodes(t *testing.T) { v := valigo.New() valigo.Configure[account](v, func(c valigo.Configurator[account], m *account) { - c.Field(&m.Status).As(eq.Of).Required().OneOf(active).NotOneOf("").Equal(blocked).NotEqual("").EqualField(&m.Previous) + c.Field(&m.Status).As(eq.Of).Required().OneOf(active).NotOneOf("").Equal(blocked).NotEqual("").EqualField(&m.Previous).NotEqualField(&m.Status) c.Slice(&m.Roles).As(eq.Slice).Unique() }) var codes []string for _, err := range v.ValidateTyped(context.Background(), &account{Previous: active, Roles: []status{active, active}}) { codes = append(codes, err.Code) } - assert.Equal(t, []string{"value.required", "value.one_of", "value.not_one_of", "value.equal", "value.not_equal", "value.equal_field", "value.unique"}, codes) + assert.Equal(t, []string{"value.required", "value.one_of", "value.not_one_of", "value.equal", "value.not_equal", "value.equal_field", "value.not_equal_field", "value.unique"}, codes) } diff --git a/rules/num/base.go b/rules/num/base.go index fcc397e..fef2647 100644 --- a/rules/num/base.go +++ b/rules/num/base.go @@ -15,6 +15,8 @@ const ( anyOfIntervalLocalKey = "validation:num:Only interval[%v - %v] is allowed" latitudeLocaleKey = "validation:num:Should be latitude" longitudeLocaleKey = "validation:num:Should be longitude" + greaterLocaleKey = "validation:num:Should be greater than %v" + lessLocaleKey = "validation:num:Should be less than %v" ) // Number is a constraint for numeric types supported by BaseConfigurator. @@ -69,6 +71,34 @@ func (i *BaseConfigurator[N]) Min(minNum N) *BaseConfigurator[N] { return i } +// GreaterThan checks if the number is greater than n. +func (i *BaseConfigurator[N]) GreaterThan(n N) *BaseConfigurator[N] { + i.f.Schema("exclusiveMinimum", n) + i.f.CheckMsg(func(v N) bool { return v > n }, shared.M("number.greater_than", greaterLocaleKey, shared.P("min", n))) + return i +} + +// LessThan checks if the number is less than n. +func (i *BaseConfigurator[N]) LessThan(n N) *BaseConfigurator[N] { + i.f.Schema("exclusiveMaximum", n) + i.f.CheckMsg(func(v N) bool { return v < n }, shared.M("number.less_than", lessLocaleKey, shared.P("max", n))) + return i +} + +// GreaterField checks if the number is greater than the value of another numeric field of the object: +// b.Field(&m.Max).As(num.Of).GreaterField(&m.Min). +func (i *BaseConfigurator[N]) GreaterField(other *N) *BaseConfigurator[N] { + i.f.CheckWithMsg(other, func(v, o N) bool { return v > o }, shared.M("number.greater_field", greaterLocaleKey)) + return i +} + +// LessField checks if the number is less than the value of another numeric field of the object: +// b.Field(&m.Min).As(num.Of).LessField(&m.Max). +func (i *BaseConfigurator[N]) LessField(other *N) *BaseConfigurator[N] { + i.f.CheckWithMsg(other, func(v, o N) bool { return v < o }, shared.M("number.less_field", lessLocaleKey)) + return i +} + // MinField checks if the number is not less than the value of another numeric field of the object: // b.Field(&m.Price).As(num.Of).MinField(&m.MinPrice). func (i *BaseConfigurator[N]) MinField(other *N) *BaseConfigurator[N] { diff --git a/rules/num/base_test.go b/rules/num/base_test.go index aa386e4..6f335b7 100644 --- a/rules/num/base_test.go +++ b/rules/num/base_test.go @@ -125,11 +125,12 @@ func TestCodes(t *testing.T) { v := valigo.New() valigo.Configure[numbers](v, func(c valigo.Configurator[numbers], m *numbers) { c.Field(&m.Int).As(num.Of).Required().Min(5).Max(-1).MinField(&m.Min).MaxField(&m.Max).AnyOf(7).AnyOfInterval(1, 2) - c.Field(&m.Float64).As(num.Of).Latitude().Longitude() + c.Field(&m.Float64).As(num.Of).Latitude().Longitude().GreaterThan(300).LessThan(100).GreaterField(&m.Float64).LessField(&m.Float64) }) var codes []string for _, err := range v.ValidateTyped(context.Background(), &numbers{Min: 1, Max: -1, Float64: 200}) { codes = append(codes, err.Code) } - assert.Equal(t, []string{"number.required", "number.min", "number.max", "number.min_field", "number.max_field", "number.any_of", "number.interval", "number.latitude", "number.longitude"}, codes) + assert.Equal(t, []string{"number.required", "number.min", "number.max", "number.min_field", "number.max_field", "number.any_of", "number.interval", "number.latitude", "number.longitude", + "number.greater_than", "number.less_than", "number.greater_field", "number.less_field"}, codes) } diff --git a/rules/str/base.go b/rules/str/base.go index 97a74e0..7bf66cc 100644 --- a/rules/str/base.go +++ b/rules/str/base.go @@ -12,39 +12,50 @@ import ( ) const ( - minLengthLocaleKey = "validation:string:Cannot be shorter than %d characters" - maxLengthLocaleKey = "validation:string:Cannot be longer than %d characters" - requiredLocaleKey = "validation:string:Should be fulfilled" - regexpLocaleKey = "validation:string:Doesn't match required regexp pattern" - anyOfLocaleKey = "validation:string:Only %s values is allowed" - emailLocaleKey = "validation:string:Should be email address" - urlLocaleKey = "validation:string:Should be URL" - ipLocaleKey = "validation:string:Should be IP address" - ipv4LocaleKey = "validation:string:Should be IPv4 address" - ipv6LocaleKey = "validation:string:Should be IPv6 address" - hostnameLocaleKey = "validation:string:Should be hostname" - uuidLocaleKey = "validation:string:Should be UUID" - alnumLocaleKey = "validation:string:Should contain only letters and digits" - prefixLocaleKey = "validation:string:Should start with %s" - suffixLocaleKey = "validation:string:Should end with %s" - containsLocaleKey = "validation:string:Should contain %s" - equalFieldKey = "validation:string:Should be equal to %s" - base64LocaleKey = "validation:string:Should be base64 encoded" - base64URLLocaleKey = "validation:string:Should be base64url encoded" - jsonLocaleKey = "validation:string:Should be JSON" - semverLocaleKey = "validation:string:Should be semantic version" - cidrLocaleKey = "validation:string:Should be CIDR" - macLocaleKey = "validation:string:Should be MAC address" - e164LocaleKey = "validation:string:Should be E.164 phone number" - hexColorLocaleKey = "validation:string:Should be hex color" - asciiLocaleKey = "validation:string:Should contain only ASCII characters" - lowercaseLocaleKey = "validation:string:Should be lowercase" - uppercaseLocaleKey = "validation:string:Should be uppercase" - datetimeLocaleKey = "validation:string:Should be date and time in %s format" - countryLocaleKey = "validation:string:Should be ISO 3166-1 alpha-2 country code" - currencyLocaleKey = "validation:string:Should be ISO 4217 currency code" - luhnLocaleKey = "validation:string:Should have valid Luhn checksum" - cardLocaleKey = "validation:string:Should be credit card number" + minLengthLocaleKey = "validation:string:Cannot be shorter than %d characters" + maxLengthLocaleKey = "validation:string:Cannot be longer than %d characters" + requiredLocaleKey = "validation:string:Should be fulfilled" + regexpLocaleKey = "validation:string:Doesn't match required regexp pattern" + anyOfLocaleKey = "validation:string:Only %s values is allowed" + emailLocaleKey = "validation:string:Should be email address" + urlLocaleKey = "validation:string:Should be URL" + ipLocaleKey = "validation:string:Should be IP address" + ipv4LocaleKey = "validation:string:Should be IPv4 address" + ipv6LocaleKey = "validation:string:Should be IPv6 address" + hostnameLocaleKey = "validation:string:Should be hostname" + uuidLocaleKey = "validation:string:Should be UUID" + alnumLocaleKey = "validation:string:Should contain only letters and digits" + prefixLocaleKey = "validation:string:Should start with %s" + suffixLocaleKey = "validation:string:Should end with %s" + containsLocaleKey = "validation:string:Should contain %s" + equalFieldKey = "validation:string:Should be equal to %s" + base64LocaleKey = "validation:string:Should be base64 encoded" + base64URLLocaleKey = "validation:string:Should be base64url encoded" + jsonLocaleKey = "validation:string:Should be JSON" + semverLocaleKey = "validation:string:Should be semantic version" + cidrLocaleKey = "validation:string:Should be CIDR" + macLocaleKey = "validation:string:Should be MAC address" + e164LocaleKey = "validation:string:Should be E.164 phone number" + hexColorLocaleKey = "validation:string:Should be hex color" + asciiLocaleKey = "validation:string:Should contain only ASCII characters" + lowercaseLocaleKey = "validation:string:Should be lowercase" + uppercaseLocaleKey = "validation:string:Should be uppercase" + datetimeLocaleKey = "validation:string:Should be date and time in %s format" + countryLocaleKey = "validation:string:Should be ISO 3166-1 alpha-2 country code" + currencyLocaleKey = "validation:string:Should be ISO 4217 currency code" + luhnLocaleKey = "validation:string:Should have valid Luhn checksum" + cardLocaleKey = "validation:string:Should be credit card number" + alphaLocaleKey = "validation:string:Should contain only letters" + digitsLocaleKey = "validation:string:Should contain only digits" + numericLocaleKey = "validation:string:Should be a number" + hexLocaleKey = "validation:string:Should be hexadecimal" + excludesLocaleKey = "validation:string:Cannot contain %s" + containsAnyLocaleKey = "validation:string:Should contain any of the characters %s" + excludesAnyLocaleKey = "validation:string:Cannot contain the characters %s" + equalFoldLocaleKey = "validation:string:Should be equal to %s ignoring case" + notPrefixLocaleKey = "validation:string:Cannot start with %s" + notSuffixLocaleKey = "validation:string:Cannot end with %s" + notEqualFieldKey = "validation:string:Cannot be equal to %s" ) var emailRegexp = regexp.MustCompile(`^[^\s,@#$%^&*!()]+@([a-zA-Z0-9]+[.])+[a-zA-Z]{2,8}$`) @@ -223,6 +234,77 @@ func (i *BaseConfigurator) Contains(substr string) *BaseConfigurator { return i } +// Excludes checks if the string doesn't contain substr. +func (i *BaseConfigurator) Excludes(substr string) *BaseConfigurator { + i.f.CheckMsg(func(v string) bool { return !strings.Contains(v, substr) }, shared.M("string.excludes", excludesLocaleKey, shared.P("substring", substr))) + return i +} + +// ContainsAny checks if the string contains any of the characters of chars. +func (i *BaseConfigurator) ContainsAny(chars string) *BaseConfigurator { + i.f.CheckMsg(func(v string) bool { return strings.ContainsAny(v, chars) }, shared.M("string.contains_any", containsAnyLocaleKey, shared.P("chars", chars))) + return i +} + +// ExcludesAny checks if the string contains none of the characters of chars. +func (i *BaseConfigurator) ExcludesAny(chars string) *BaseConfigurator { + i.f.CheckMsg(func(v string) bool { return !strings.ContainsAny(v, chars) }, shared.M("string.excludes_any", excludesAnyLocaleKey, shared.P("chars", chars))) + return i +} + +// NotPrefix checks if the string doesn't start with prefix. +func (i *BaseConfigurator) NotPrefix(prefix string) *BaseConfigurator { + i.f.CheckMsg(func(v string) bool { return !strings.HasPrefix(v, prefix) }, shared.M("string.not_prefix", notPrefixLocaleKey, shared.P("prefix", prefix))) + return i +} + +// NotSuffix checks if the string doesn't end with suffix. +func (i *BaseConfigurator) NotSuffix(suffix string) *BaseConfigurator { + i.f.CheckMsg(func(v string) bool { return !strings.HasSuffix(v, suffix) }, shared.M("string.not_suffix", notSuffixLocaleKey, shared.P("suffix", suffix))) + return i +} + +// EqualFold checks if the string is equal to value ignoring case, by Unicode case folding. +func (i *BaseConfigurator) EqualFold(value string) *BaseConfigurator { + i.f.CheckMsg(func(v string) bool { return strings.EqualFold(v, value) }, shared.M("string.equal_fold", equalFoldLocaleKey, shared.P("value", value))) + return i +} + +// NotEqualField checks if the string differs from the value of another string field of the object: +// b.Field(&m.NewPassword).As(str.Of).NotEqualField(&m.OldPassword). +func (i *BaseConfigurator) NotEqualField(other *string) *BaseConfigurator { + i.f.CheckWithMsg(other, func(v, o string) bool { return v != o }, shared.M("string.not_equal_field", notEqualFieldKey)) + return i +} + +// Alpha checks if the string is not empty and has only ASCII letters. +func (i *BaseConfigurator) Alpha() *BaseConfigurator { + i.f.Schema("pattern", "^[a-zA-Z]+$") + i.f.CheckMsg(isAlpha, shared.M("string.alpha", alphaLocaleKey)) + return i +} + +// Digits checks if the string is not empty and has only ASCII digits: 0042. +func (i *BaseConfigurator) Digits() *BaseConfigurator { + i.f.Schema("pattern", "^[0-9]+$") + i.f.CheckMsg(isDigits, shared.M("string.digits", digitsLocaleKey)) + return i +} + +// Numeric checks if the string is a decimal number with an optional sign and fraction: -12, +3.5. +func (i *BaseConfigurator) Numeric() *BaseConfigurator { + i.f.Schema("pattern", `^[-+]?[0-9]+(\.[0-9]+)?$`) + i.f.CheckMsg(isNumeric, shared.M("string.numeric", numericLocaleKey)) + return i +} + +// Hexadecimal checks if the string is a hexadecimal number with an optional 0x prefix: ff, 0x1A. +func (i *BaseConfigurator) Hexadecimal() *BaseConfigurator { + i.f.Schema("pattern", "^(0[xX])?[0-9a-fA-F]+$") + i.f.CheckMsg(isHexadecimal, shared.M("string.hexadecimal", hexLocaleKey)) + return i +} + // Base64 checks if the string is base64 of RFC 4648 with padding, the standard alphabet. func (i *BaseConfigurator) Base64() *BaseConfigurator { i.f.Schema("contentEncoding", "base64") diff --git a/rules/str/base_test.go b/rules/str/base_test.go index d662312..b05ac25 100644 --- a/rules/str/base_test.go +++ b/rules/str/base_test.go @@ -72,6 +72,25 @@ func TestRules(t *testing.T) { {"hostname", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Hostname() }, &texts{Name: "a_b"}, []string{"Name: Should be hostname"}}, {"uuid", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).UUID() }, &texts{Name: "nope"}, []string{"Name: Should be UUID"}}, {"alphanumeric", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Alphanumeric() }, &texts{Name: "a-b"}, []string{"Name: Should contain only letters and digits"}}, + {"excludes", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Excludes("b") }, &texts{Name: "ab"}, []string{"Name: Cannot contain b"}}, + {"contains any", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).ContainsAny("xy") }, &texts{Name: "ab"}, []string{"Name: Should contain any of the characters xy"}}, + {"excludes any", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).ExcludesAny("xb") }, &texts{Name: "ab"}, []string{"Name: Cannot contain the characters xb"}}, + {"not prefix", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).NotPrefix("a") }, &texts{Name: "ab"}, []string{"Name: Cannot start with a"}}, + {"not suffix", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).NotSuffix("b") }, &texts{Name: "ab"}, []string{"Name: Cannot end with b"}}, + {"equal fold", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).EqualFold("abc") }, &texts{Name: "ab"}, []string{"Name: Should be equal to abc ignoring case"}}, + {"alpha", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Alpha() }, &texts{Name: "a1"}, []string{"Name: Should contain only letters"}}, + {"digits", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Digits() }, &texts{Name: "1a"}, []string{"Name: Should contain only digits"}}, + {"numeric", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Numeric() }, &texts{Name: "1."}, []string{"Name: Should be a number"}}, + {"hexadecimal", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Hexadecimal() }, &texts{Name: "0xg"}, []string{"Name: Should be hexadecimal"}}, + {"negative rules ok", func(c valigo.Configurator[texts], m *texts) { + c.Field(&m.Name).As(str.Of).Excludes("x").ContainsAny("b").ExcludesAny("xy").NotPrefix("b").NotSuffix("a").EqualFold("AB").Alpha() + }, &texts{Name: "ab"}, nil}, + {"number rules ok", func(c valigo.Configurator[texts], m *texts) { + c.Field(&m.Name).As(str.Of).Digits().Numeric().Hexadecimal() + }, &texts{Name: "0042"}, nil}, + {"signed numeric ok", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Numeric() }, &texts{Name: "-3.25"}, nil}, + {"hex prefix ok", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Hexadecimal() }, &texts{Name: "0xFF"}, nil}, + {"not equal field", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).NotEqualField(&m.Repeat) }, &texts{Name: "a", Repeat: "a"}, []string{"Name: Cannot be equal to Repeat"}}, {"prefix", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Prefix("ab") }, &texts{Name: "ba"}, []string{"Name: Should start with ab"}}, {"suffix", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Suffix("ab") }, &texts{Name: "ba"}, []string{"Name: Should end with ab"}}, {"contains", func(c valigo.Configurator[texts], m *texts) { c.Field(&m.Name).As(str.Of).Contains("x") }, &texts{Name: "ba"}, []string{"Name: Should contain x"}}, @@ -190,7 +209,9 @@ func TestCodes(t *testing.T) { c.Field(&m.Name).As(str.Of).Required().MinLen(5).MaxLen(1).MinRunes(5).MaxRunes(1).AnyOf("x").Regexp(re).Email().URL(). IP().IPv4().IPv6().Hostname().UUID().Alphanumeric().Prefix("x").Suffix("x").Contains("x").EqualField(&m.Repeat). Base64().Base64URL().JSON().Semver().CIDR().MAC().E164().HexColor().ASCII().Lowercase().Uppercase().Datetime("2006"). - CountryCode().CurrencyCode().Luhn().CreditCard() + CountryCode().CurrencyCode().Luhn().CreditCard(). + Excludes(" ").ContainsAny("xyz").ExcludesAny("ab").NotPrefix("a").NotSuffix("b").EqualFold("X").NotEqualField(&m.Name). + Alpha().Digits().Numeric().Hexadecimal() }) var codes []string params := map[string]map[string]any{} @@ -205,7 +226,11 @@ func TestCodes(t *testing.T) { "string.base64", "string.base64url", "string.json", "string.semver", "string.cidr", "string.mac", "string.e164", "string.hex_color", "string.uppercase", "string.datetime", "string.country_code", "string.currency_code", "string.luhn", "string.credit_card", + "string.excludes", "string.contains_any", "string.excludes_any", "string.not_prefix", "string.not_suffix", + "string.equal_fold", "string.not_equal_field", "string.alpha", "string.digits", "string.numeric", "string.hexadecimal", }, codes) + assert.Equal(t, map[string]any{"chars": "xyz"}, params["string.contains_any"]) + assert.Equal(t, map[string]any{"value": "X"}, params["string.equal_fold"]) assert.Equal(t, map[string]any{"layout": "2006"}, params["string.datetime"]) assert.Equal(t, map[string]any{"min": 5}, params["string.min_len"]) assert.Equal(t, map[string]any{"values": []string{"x"}}, params["string.any_of"]) diff --git a/rules/str/format.go b/rules/str/format.go index d6ded53..3d2ae65 100644 --- a/rules/str/format.go +++ b/rules/str/format.go @@ -314,3 +314,52 @@ func isDatetime(layout string) func(s string) bool { return err == nil } } + +func isAlpha(s string) bool { + if s == "" { + return false + } + for i := 0; i < len(s); i++ { + if !isASCIILetter(s[i]) { + return false + } + } + return true +} + +func isDigits(s string) bool { + if s == "" { + return false + } + for i := 0; i < len(s); i++ { + if !isASCIIDigit(s[i]) { + return false + } + } + return true +} + +// isNumeric reports whether s is [-+]digits[.digits]. +func isNumeric(s string) bool { + if s != "" && (s[0] == '-' || s[0] == '+') { + s = s[1:] + } + whole, fraction, dot := strings.Cut(s, ".") + return isDigits(whole) && (!dot || isDigits(fraction)) +} + +// isHexadecimal reports whether s is [0x]hexdigits. +func isHexadecimal(s string) bool { + if len(s) > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X') { + s = s[2:] + } + if s == "" { + return false + } + for i := 0; i < len(s); i++ { + if !isHex(s[i]) { + return false + } + } + return true +} diff --git a/rules/str/format_test.go b/rules/str/format_test.go index 4b23958..27e6930 100644 --- a/rules/str/format_test.go +++ b/rules/str/format_test.go @@ -186,3 +186,10 @@ func TestCodesDontAllocate(t *testing.T) { } } } + +func TestNumberFormats(t *testing.T) { + check(t, "numeric", isNumeric, []string{"1", "+1", "-1.5", "0042"}, []string{"", "1.", ".5", "-", "1.2.3", "1e3"}) + check(t, "hexadecimal", isHexadecimal, []string{"0x1f", "FF", "0X0", "0"}, []string{"", "0x", "g", "0xg"}) + check(t, "alpha", isAlpha, []string{"abc", "XyZ"}, []string{"", "a1", "é"}) + check(t, "digits", isDigits, []string{"0", "0042"}, []string{"", "-1", "1.5"}) +} diff --git a/skills/valigo/SKILL.md b/skills/valigo/SKILL.md index 24d6793..938d36a 100644 --- a/skills/valigo/SKILL.md +++ b/skills/valigo/SKILL.md @@ -25,10 +25,10 @@ Rules are configured once by `valigo.Configure[T]` with pointers to the fields o | Configurator | Rules | |---|---| -| `b.Field(&m.S).As(str.Of)` | `Required`, `MinLen`/`MaxLen` (bytes), `MinRunes`/`MaxRunes` (characters), `AnyOf`, `EqualField(&m.Other)`, `Prefix`, `Suffix`, `Contains`, `Regexp(re, str.WithRegexpLocaleKey(key))`, `Email`, `URL`, `IP`, `IPv4`, `IPv6`, `CIDR`, `MAC`, `Hostname`, `UUID`, `Alphanumeric`, `ASCII`, `Lowercase`, `Uppercase`, `Base64`, `Base64URL`, `JSON`, `Semver`, `E164`, `HexColor`, `Datetime(layout)`, `CountryCode`, `CurrencyCode`, `Luhn`, `CreditCard`, `Trim`, `Custom`, `When`; formats fail on empty strings | -| `b.Field(&m.N).As(num.Of)`, `b.Field(&m.P).As(num.Ptr)` | `Required` (zero for `num.Of`, nil for `num.Ptr`), `Min`, `Max`, `MinField(&m.Other)`, `MaxField(&m.Other)`, `AnyOf`, `AnyOfInterval` (inclusive), `Latitude`, `Longitude`, `Custom`, `When`; slices: `b.Slice(&m.Sizes).As(num.Slice)` | +| `b.Field(&m.S).As(str.Of)` | `Required`, `MinLen`/`MaxLen` (bytes), `MinRunes`/`MaxRunes` (characters), `AnyOf`, `EqualField(&m.Other)`, `NotEqualField(&m.Other)`, `EqualFold`, `Prefix`, `Suffix`, `Contains`, `NotPrefix`, `NotSuffix`, `Excludes`, `ContainsAny`, `ExcludesAny`, `Alpha`, `Digits`, `Numeric`, `Hexadecimal`, `Regexp(re, str.WithRegexpLocaleKey(key))`, `Email`, `URL`, `IP`, `IPv4`, `IPv6`, `CIDR`, `MAC`, `Hostname`, `UUID`, `Alphanumeric`, `ASCII`, `Lowercase`, `Uppercase`, `Base64`, `Base64URL`, `JSON`, `Semver`, `E164`, `HexColor`, `Datetime(layout)`, `CountryCode`, `CurrencyCode`, `Luhn`, `CreditCard`, `Trim`, `Custom`, `When`; formats fail on empty strings | +| `b.Field(&m.N).As(num.Of)`, `b.Field(&m.P).As(num.Ptr)` | `Required` (zero for `num.Of`, nil for `num.Ptr`), `Min`, `Max`, `GreaterThan`, `LessThan`, `MinField(&m.Other)`, `MaxField(&m.Other)`, `GreaterField(&m.Other)`, `LessField(&m.Other)`, `AnyOf`, `AnyOfInterval` (inclusive), `Latitude`, `Longitude`, `Custom`, `When`; slices: `b.Slice(&m.Sizes).As(num.Slice)` | | `b.Field(&m.At).As(timex.Of)` | `time.Time` and `*time.Time`: `Required` (not zero), `Before`, `After`, `Between` (inclusive), `BeforeField(&m.Other)`, `AfterField(&m.Other)`, `InPast`, `InFuture`, `Custom`, `When`; slices: `b.Slice(&m.Dates).As(timex.Slice)` | -| `b.Field(&m.Status).As(eq.Of)`, `.As(eq.Ptr)` | any `comparable` (enums of named types, `bool`): `Required` (not zero / not nil), `OneOf`, `NotOneOf`, `Equal`, `NotEqual`, `EqualField(&m.Other)`, `Custom`, `When`; `b.Slice(&m.Roles).As(eq.Slice)`: `Unique`, `OneOf`, `Each` | +| `b.Field(&m.Status).As(eq.Of)`, `.As(eq.Ptr)` | any `comparable` (enums of named types, `bool`): `Required` (not zero / not nil), `OneOf`, `NotOneOf`, `Equal`, `NotEqual`, `EqualField(&m.Other)`, `NotEqualField(&m.Other)`, `Custom`, `When`; `b.Slice(&m.Roles).As(eq.Slice)`: `Unique`, `OneOf`, `Each` | | `b.Field(&m.ID).As(vuuid.Of)` | `Required` (not `uuid.Nil`), `AnyOf`, `Custom`, `When` | | `b.Slice(&m.Items)` | `Required`, `MinLen`, `MaxLen`, `Custom`, `When`, `Each(func(*shared.Field[E]))` with `Check(ok, message)`, `Required(ok, message)`, `As` to convert the element: `e.As(num.Of).Min(1)` | | `b.Slice(&m.Tags).As(str.Slice)` | the rules of the slice and `Each(func(*str.BaseConfigurator))`, `Trim`, `Regexp`, `Email` | diff --git a/translator/locales/de/data.yaml b/translator/locales/de/data.yaml index 2b57d9d..a0a9e37 100644 --- a/translator/locales/de/data.yaml +++ b/translator/locales/de/data.yaml @@ -38,6 +38,17 @@ validation: "Should be ISO 4217 currency code": Muss ein Währungscode nach ISO 4217 sein "Should have valid Luhn checksum": Muss eine gültige Luhn-Prüfsumme haben "Should be credit card number": Muss eine Kreditkartennummer sein + "Should contain only letters": "Darf nur Buchstaben enthalten" + "Should contain only digits": "Darf nur Ziffern enthalten" + "Should be a number": "Muss eine Zahl sein" + "Should be hexadecimal": "Muss hexadezimal sein" + "Cannot contain %s": "Darf %s nicht enthalten" + "Should contain any of the characters %s": "Muss eines der Zeichen %s enthalten" + "Cannot contain the characters %s": "Darf die Zeichen %s nicht enthalten" + "Should be equal to %s ignoring case": "Muss ohne Beachtung der Groß- und Kleinschreibung gleich %s sein" + "Cannot start with %s": "Darf nicht mit %s beginnen" + "Cannot end with %s": "Darf nicht mit %s enden" + "Cannot be equal to %s": "Darf nicht gleich %s sein" num: "Cannot be less than %v": Darf nicht kleiner als %v sein "Cannot be greater than %v": Darf nicht größer als %v sein @@ -47,6 +58,8 @@ validation: "Invalid value": Ungültiger Wert "Should be latitude": Muss ein Breitengrad sein "Should be longitude": Muss ein Längengrad sein + "Should be greater than %v": "Muss größer als %v sein" + "Should be less than %v": "Muss kleiner als %v sein" time: "Should be fulfilled": Muss ausgefüllt sein "Should be before %s": Muss vor %s liegen @@ -62,6 +75,7 @@ validation: "Should be %v": Muss %v sein "Cannot be %v": Darf nicht %v sein "Should contain unique values": Darf nur eindeutige Werte enthalten + "Cannot be equal to %s": "Darf nicht gleich %s sein" uuid: "Should be fulfilled": Muss ausgefüllt sein "Only %s values is allowed": Nur die Werte %s sind erlaubt diff --git a/translator/locales/en/data.yaml b/translator/locales/en/data.yaml index 97388c0..6483a1f 100644 --- a/translator/locales/en/data.yaml +++ b/translator/locales/en/data.yaml @@ -38,6 +38,17 @@ validation: "Should be ISO 4217 currency code": Should be ISO 4217 currency code "Should have valid Luhn checksum": Should have valid Luhn checksum "Should be credit card number": Should be credit card number + "Should contain only letters": "Should contain only letters" + "Should contain only digits": "Should contain only digits" + "Should be a number": "Should be a number" + "Should be hexadecimal": "Should be hexadecimal" + "Cannot contain %s": "Cannot contain %s" + "Should contain any of the characters %s": "Should contain any of the characters %s" + "Cannot contain the characters %s": "Cannot contain the characters %s" + "Should be equal to %s ignoring case": "Should be equal to %s ignoring case" + "Cannot start with %s": "Cannot start with %s" + "Cannot end with %s": "Cannot end with %s" + "Cannot be equal to %s": "Cannot be equal to %s" num: "Cannot be less than %v": Cannot be less than %v "Cannot be greater than %v": Cannot be greater than %v @@ -47,6 +58,8 @@ validation: "Invalid value": Invalid value "Should be latitude": Should be latitude "Should be longitude": Should be longitude + "Should be greater than %v": "Should be greater than %v" + "Should be less than %v": "Should be less than %v" time: "Should be fulfilled": Should be fulfilled "Should be before %s": Should be before %s @@ -62,6 +75,7 @@ validation: "Should be %v": Should be %v "Cannot be %v": Cannot be %v "Should contain unique values": Should contain unique values + "Cannot be equal to %s": "Cannot be equal to %s" uuid: "Should be fulfilled": Should be fulfilled "Only %s values is allowed": Only %s values is allowed diff --git a/translator/locales/es/data.yaml b/translator/locales/es/data.yaml index 2862138..fa03314 100644 --- a/translator/locales/es/data.yaml +++ b/translator/locales/es/data.yaml @@ -38,6 +38,17 @@ validation: "Should be ISO 4217 currency code": Debe ser un código de moneda ISO 4217 "Should have valid Luhn checksum": Debe tener una suma de verificación Luhn válida "Should be credit card number": Debe ser un número de tarjeta de crédito + "Should contain only letters": "Solo puede contener letras" + "Should contain only digits": "Solo puede contener dígitos" + "Should be a number": "Debe ser un número" + "Should be hexadecimal": "Debe ser hexadecimal" + "Cannot contain %s": "No puede contener %s" + "Should contain any of the characters %s": "Debe contener alguno de los caracteres %s" + "Cannot contain the characters %s": "No puede contener los caracteres %s" + "Should be equal to %s ignoring case": "Debe ser igual a %s sin distinguir mayúsculas y minúsculas" + "Cannot start with %s": "No puede empezar por %s" + "Cannot end with %s": "No puede terminar en %s" + "Cannot be equal to %s": "No puede ser igual a %s" num: "Cannot be less than %v": No puede ser menor que %v "Cannot be greater than %v": No puede ser mayor que %v @@ -47,6 +58,8 @@ validation: "Invalid value": Valor no válido "Should be latitude": Debe ser una latitud "Should be longitude": Debe ser una longitud + "Should be greater than %v": "Debe ser mayor que %v" + "Should be less than %v": "Debe ser menor que %v" time: "Should be fulfilled": Es obligatorio "Should be before %s": Debe ser anterior a %s @@ -62,6 +75,7 @@ validation: "Should be %v": Debe ser %v "Cannot be %v": No puede ser %v "Should contain unique values": Debe contener valores únicos + "Cannot be equal to %s": "No puede ser igual a %s" uuid: "Should be fulfilled": Es obligatorio "Only %s values is allowed": Solo se permiten los valores %s diff --git a/translator/locales/fr/data.yaml b/translator/locales/fr/data.yaml index 6b1daef..b9d684a 100644 --- a/translator/locales/fr/data.yaml +++ b/translator/locales/fr/data.yaml @@ -38,6 +38,17 @@ validation: "Should be ISO 4217 currency code": Doit être un code de devise ISO 4217 "Should have valid Luhn checksum": Doit avoir une somme de contrôle de Luhn valide "Should be credit card number": Doit être un numéro de carte bancaire + "Should contain only letters": "Ne doit contenir que des lettres" + "Should contain only digits": "Ne doit contenir que des chiffres" + "Should be a number": "Doit être un nombre" + "Should be hexadecimal": "Doit être hexadécimal" + "Cannot contain %s": "Ne peut pas contenir %s" + "Should contain any of the characters %s": "Doit contenir l'un des caractères %s" + "Cannot contain the characters %s": "Ne peut pas contenir les caractères %s" + "Should be equal to %s ignoring case": "Doit être égal à %s sans tenir compte de la casse" + "Cannot start with %s": "Ne peut pas commencer par %s" + "Cannot end with %s": "Ne peut pas se terminer par %s" + "Cannot be equal to %s": "Ne peut pas être égal à %s" num: "Cannot be less than %v": Ne peut pas être inférieur à %v "Cannot be greater than %v": Ne peut pas être supérieur à %v @@ -47,6 +58,8 @@ validation: "Invalid value": Valeur invalide "Should be latitude": Doit être une latitude "Should be longitude": Doit être une longitude + "Should be greater than %v": "Doit être supérieur à %v" + "Should be less than %v": "Doit être inférieur à %v" time: "Should be fulfilled": Doit être renseigné "Should be before %s": Doit être antérieur à %s @@ -62,6 +75,7 @@ validation: "Should be %v": Doit être %v "Cannot be %v": Ne peut pas être %v "Should contain unique values": Doit contenir des valeurs uniques + "Cannot be equal to %s": "Ne peut pas être égal à %s" uuid: "Should be fulfilled": Doit être renseigné "Only %s values is allowed": Seules les valeurs %s sont autorisées diff --git a/translator/locales/ru/data.yaml b/translator/locales/ru/data.yaml index a003497..c5eb6f4 100644 --- a/translator/locales/ru/data.yaml +++ b/translator/locales/ru/data.yaml @@ -42,6 +42,17 @@ validation: "Should be ISO 4217 currency code": Должно быть кодом валюты ISO 4217 "Should have valid Luhn checksum": Должно иметь верную контрольную сумму по алгоритму Луна "Should be credit card number": Должно быть номером банковской карты + "Should contain only letters": "Должно содержать только латинские буквы" + "Should contain only digits": "Должно содержать только цифры" + "Should be a number": "Должно быть числом" + "Should be hexadecimal": "Должно быть шестнадцатеричным числом" + "Cannot contain %s": "Не может содержать %s" + "Should contain any of the characters %s": "Должно содержать один из символов %s" + "Cannot contain the characters %s": "Не может содержать символы %s" + "Should be equal to %s ignoring case": "Должно совпадать с %s без учёта регистра" + "Cannot start with %s": "Не может начинаться с %s" + "Cannot end with %s": "Не может заканчиваться на %s" + "Cannot be equal to %s": "Не может совпадать с %s" num: "Cannot be less than %v": Не может быть меньше %v "Cannot be greater than %v": Не может быть больше %v @@ -51,6 +62,8 @@ validation: "Invalid value": Невалидное значение "Should be latitude": Должно быть широтой "Should be longitude": Должно быть долготой + "Should be greater than %v": "Должно быть больше %v" + "Should be less than %v": "Должно быть меньше %v" time: "Should be fulfilled": Должно быть заполнено "Should be before %s": Должно быть раньше %s @@ -66,6 +79,7 @@ validation: "Should be %v": Должно быть %v "Cannot be %v": Не может быть %v "Should contain unique values": Должно содержать уникальные значения + "Cannot be equal to %s": "Не может совпадать с %s" uuid: "Should be fulfilled": Должно быть заполнено "Only %s values is allowed": Только %s значения разрешены