StringRules describes the rules applied to string values These
rules may also be applied to the google.protobuf.StringValue Well-Known-Type.
StringRules describes the rules applied to string values These
rules may also be applied to the google.protobuf.StringValue Well-Known-Type.
Optional[customReturns a safe value for JSON logs.
Returns a safe value for JSON logs.
Optional[unknownPreserves protobuf fields that this SDK version does not recognize.
Contains the fully qualified protobuf type name.
Optionalconstconst requires the field value to exactly match the specified value. If
the field value doesn't match, an error message is generated.
message MyString {
// value must equal `hello`
string value = 1 [(buf.validate.field).string.const = "hello"];
}
Optionalcontainscontains specifies that the field value must have the
specified substring anywhere in the string. If the field value doesn't
contain the specified substring, an error message will be generated.
message MyString {
// value does not contain substring `inside`.
string value = 1 [(buf.validate.field).string.contains = "inside"];
}
example specifies values that the field may have. These values SHOULD
conform to other rules. example values will not impact validation
but may be used as helpful guidance on how to populate the given field.
message MyString {
string value = 1 [
(buf.validate.field).string.example = "hello",
(buf.validate.field).string.example = "world"
];
}
in specifies that the field value must be equal to one of the specified
values. If the field value isn't one of the specified values, an error
message will be generated.
message MyString {
// value must be in list ["apple", "banana"]
string value = 1 [(buf.validate.field).string.in = "apple", (buf.validate.field).string.in = "banana"];
}
Optionallenlen dictates that the field value must have the specified
number of characters (Unicode code points), which may differ from the number
of bytes in the string. If the field value does not meet the specified
length, an error message will be generated.
message MyString {
// value length must be 5 characters
string value = 1 [(buf.validate.field).string.len = 5];
}
Optionallenlen_bytes dictates that the field value must have the specified number of
bytes. If the field value does not match the specified length in bytes,
an error message will be generated.
message MyString {
// value length must be 6 bytes
string value = 1 [(buf.validate.field).string.len_bytes = 6];
}
Optionalmaxmax_bytes specifies that the field value must have no more than the
specified number of bytes. If the field value contains more bytes, an
error message will be generated.
message MyString {
// value length must be at most 8 bytes
string value = 1 [(buf.validate.field).string.max_bytes = 8];
}
Optionalmaxmax_len specifies that the field value must have no more than the specified
number of characters (Unicode code points), which may differ from the
number of bytes in the string. If the field value contains more characters,
an error message will be generated.
message MyString {
// value length must be at most 10 characters
string value = 1 [(buf.validate.field).string.max_len = 10];
}
Optionalminmin_bytes specifies that the field value must have at least the specified
number of bytes. If the field value contains fewer bytes, an error message
will be generated.
message MyString {
// value length must be at least 4 bytes
string value = 1 [(buf.validate.field).string.min_bytes = 4];
}
Optionalminmin_len specifies that the field value must have at least the specified
number of characters (Unicode code points), which may differ from the number
of bytes in the string. If the field value contains fewer characters, an error
message will be generated.
message MyString {
// value length must be at least 3 characters
string value = 1 [(buf.validate.field).string.min_len = 3];
}
Optionalnotnot_contains specifies that the field value must not have the
specified substring anywhere in the string. If the field value contains
the specified substring, an error message will be generated.
message MyString {
// value contains substring `inside`.
string value = 1 [(buf.validate.field).string.not_contains = "inside"];
}
not_in specifies that the field value cannot be equal to any
of the specified values. If the field value is one of the specified values,
an error message will be generated.
message MyString {
// value must not be in list ["orange", "grape"]
string value = 1 [(buf.validate.field).string.not_in = "orange", (buf.validate.field).string.not_in = "grape"];
}
Optionalpatternpattern specifies that the field value must match the specified
regular expression (RE2 syntax), with the expression provided without any
delimiters. If the field value doesn't match the regular expression, an
error message will be generated.
message MyString {
// value does not match regex pattern `^[a-zA-Z]//$`
string value = 1 [(buf.validate.field).string.pattern = "^[a-zA-Z]//$"];
}
Optionalprefixprefix specifies that the field value must have the
specified substring at the beginning of the string. If the field value
doesn't start with the specified prefix, an error message will be
generated.
message MyString {
// value does not have prefix `pre`
string value = 1 [(buf.validate.field).string.prefix = "pre"];
}
OptionalstrictThis applies to regexes HTTP_HEADER_NAME and HTTP_HEADER_VALUE to
enable strict header validation. By default, this is true, and HTTP header
validations are RFC-compliant. Setting to false will enable looser
validations that only disallow \r\n\0 characters, which can be used to
bypass header matching rules.
message MyString {
// The field `value` must have be a valid HTTP headers, but not enforced with strict rules.
string value = 1 [(buf.validate.field).string.strict = false];
}
Optionalsuffixsuffix specifies that the field value must have the
specified substring at the end of the string. If the field value doesn't
end with the specified suffix, an error message will be generated.
message MyString {
// value does not have suffix `post`
string value = 1 [(buf.validate.field).string.suffix = "post"];
}
OptionalwellWellKnown rules provide advanced rules against common string
patterns.
Contains the case.
Contains the email.
Contains the case.
Contains the hostname.
Contains the case.
Contains the ip.
Contains the case.
Contains the ipv4.
Contains the case.
Contains the ipv6.
Contains the case.
Contains the uri.
Contains the case.
Contains the uri ref.
Contains the case.
Contains the address.
Contains the case.
Contains the uuid.
Contains the case.
Contains the tuuid.
Contains the case.
Contains the ip with prefixlen.
Contains the case.
Contains the ipv4 with prefixlen.
Contains the case.
Contains the ipv6 with prefixlen.
Contains the case.
Contains the ip prefix.
Contains the case.
Contains the ipv4 prefix.
Contains the case.
Contains the ipv6 prefix.
Contains the case.
Contains the host and port.
Contains the case.
Contains the ulid.
Contains the case.
Contains the well known regex.
StringRules describes the rules applied to
stringvalues These rules may also be applied to thegoogle.protobuf.StringValueWell-Known-Type.