Skip to main content

regex

Function regex 

Source
pub fn regex(
    pattern: impl Into<String>,
    msg: impl Into<String>,
) -> impl Fn(&str) -> Result<(), String>
Expand description

Match the input against a minimal glob-style pattern.

This is not a full regular-expression engine. The supported syntax is a small literal matcher:

  • . matches any single character.
  • * matches zero or more of any character (greedy, with backtracking).
  • ^ at the start anchors to the beginning (implied; always anchored).
  • $ at the end anchors to the end (implied; always anchored).
  • any other character matches itself literally.

The whole input must match (the pattern is fully anchored). For real PCRE support, wrap the regex crate in your own closure — SLT intentionally ships no regex dependency.

§Example

// Three-letter code followed by digits, e.g. "ABC123".
let field = FormField::new("Code").validate(validators::regex("...*", "bad code"));