Keats / validator

Simple validation for Rust structs
MIT License
1.91k stars 140 forks source link

Is that possible to use `regex_lite` or other regex compatible library for regex validation? #332

Open forest1102 opened 1 month ago

forest1102 commented 1 month ago

I want to use regex_lite::Regex to validate pattern for better compilation time.
However, current derive only allows regex::Regex.

use validator::Validate;
use once_cell::sync::Lazy;
use regex_lite::Regex;

static RE_TWO_CHARS: Lazy<Regex> = Lazy::new(|| Regex::new(r"[a-z]{2}$").unwrap());
#[derive(Validate)]
#[serde(rename_all = "camelCase")]
pub struct ProjectAbstractJdto {
    #[validate(regex(path = "RE_TWO_CHARS"))]
    pub name: String,
}