pub struct RegexField {
pub name: String,
pub label: Option<String>,
pub required: bool,
pub help_text: Option<String>,
pub widget: Widget,
pub initial: Option<Value>,
pub error_message: String,
pub max_length: Option<usize>,
pub min_length: Option<usize>,
/* private fields */
}Expand description
RegexField for pattern-based validation
Compiled regex is cached using OnceLock to avoid repeated
compilation which could lead to ReDoS via allocation overhead.
Fields§
§name: StringThe field name used as the form data key.
label: Option<String>Optional human-readable label for display.
required: boolWhether this field must be filled in.
help_text: Option<String>Optional help text displayed alongside the field.
widget: WidgetThe widget type used for rendering this field.
initial: Option<Value>Optional initial (default) value for the field.
error_message: StringThe error message shown when the regex does not match.
max_length: Option<usize>Maximum allowed character count.
min_length: Option<usize>Minimum required character count.
Implementations§
Source§impl RegexField
impl RegexField
Sourcepub fn new(name: String, pattern: &str) -> Result<Self, Error>
pub fn new(name: String, pattern: &str) -> Result<Self, Error>
Create a new RegexField
The regex is compiled lazily on first use and cached for subsequent calls.
§Examples
use reinhardt_forms::fields::RegexField;
let field = RegexField::new("pattern".to_string(), r"^\d+$").unwrap();
assert_eq!(field.name, "pattern");Sourcepub fn with_error_message(self, message: String) -> Self
pub fn with_error_message(self, message: String) -> Self
Overrides the default error message for validation failures.
Trait Implementations§
Source§impl Clone for RegexField
impl Clone for RegexField
Source§impl Debug for RegexField
impl Debug for RegexField
Source§impl FormField for RegexField
impl FormField for RegexField
Source§fn initial(&self) -> Option<&Value>
fn initial(&self) -> Option<&Value>
Returns the initial (default) value for this field, if any.
Source§fn clean(&self, value: Option<&Value>) -> FieldResult<Value>
fn clean(&self, value: Option<&Value>) -> FieldResult<Value>
Validates and cleans the submitted value, returning the cleaned result.
Auto Trait Implementations§
impl !Freeze for RegexField
impl RefUnwindSafe for RegexField
impl Send for RegexField
impl Sync for RegexField
impl Unpin for RegexField
impl UnsafeUnpin for RegexField
impl UnwindSafe for RegexField
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more