pub fn matches_pattern(value: &str, pattern: &str) -> boolExpand description
Check if a string matches a regex pattern.
This function is designed to be called from generated validation code. It caches compiled regex patterns for efficiency.
§Arguments
value- The string to validatepattern- The regex pattern to match against
§Returns
true if the value matches the pattern, false otherwise.
Returns false if the pattern is invalid (logs a warning).
§Example
ⓘ
use sqlmodel_core::validate::matches_pattern;
assert!(matches_pattern("test@example.com", r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"));
assert!(!matches_pattern("invalid", r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"));