Support inline regex

This commit is contained in:
Graham Esau 2021-04-16 22:31:03 +01:00
parent 5f841f2e5c
commit c013052f59
3 changed files with 23 additions and 4 deletions

View file

@ -13,6 +13,7 @@
"pair",
"regex_str1",
"regex_str2",
"regex_str3",
"required_option",
"tel",
"x"
@ -32,6 +33,10 @@
"type": "string",
"pattern": "^[Hh]ello\\b"
},
"regex_str3": {
"type": "string",
"pattern": "^\\d+$"
},
"contains_str1": {
"type": "string",
"pattern": "substring\\.\\.\\."

View file

@ -14,6 +14,8 @@ pub struct Struct {
regex_str1: String,
#[validate(regex(path = "STARTS_WITH_HELLO", code = "foo"))]
regex_str2: String,
#[validate(regex(pattern = r"^\d+$"))]
regex_str3: String,
#[validate(contains = "substring...")]
contains_str1: String,
#[validate(contains(pattern = "substring...", message = "bar"))]