pub struct AlphanumericRule {
pub mode: AlphanumericMode,
pub allow_underscore: bool,
pub allow_dash: bool,
pub allow_space: bool,
pub message: Option<String>,
}Expand description
Alphanumeric validation rule.
§Example
use skp_validator_rules::string::alphanumeric::AlphanumericRule;
use skp_validator_core::{Rule, ValidationContext};
let rule = AlphanumericRule::new();
let ctx = ValidationContext::default();
assert!(rule.validate("abc123", &ctx).is_ok());
assert!(rule.validate("abc-123", &ctx).is_err()); // Contains dashFields§
§mode: AlphanumericModeValidation mode
allow_underscore: boolAllow underscores
allow_dash: boolAllow dashes
allow_space: boolAllow spaces
message: Option<String>Custom error message
Implementations§
Source§impl AlphanumericRule
impl AlphanumericRule
Sourcepub fn letters_only(self) -> Self
pub fn letters_only(self) -> Self
Only allow letters (no digits).
Sourcepub fn digits_only(self) -> Self
pub fn digits_only(self) -> Self
Only allow digits (no letters).
Sourcepub fn allow_underscore(self) -> Self
pub fn allow_underscore(self) -> Self
Allow underscores.
Sourcepub fn allow_dash(self) -> Self
pub fn allow_dash(self) -> Self
Allow dashes.
Sourcepub fn allow_space(self) -> Self
pub fn allow_space(self) -> Self
Allow spaces.
Trait Implementations§
Source§impl Clone for AlphanumericRule
impl Clone for AlphanumericRule
Source§fn clone(&self) -> AlphanumericRule
fn clone(&self) -> AlphanumericRule
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for AlphanumericRule
impl Debug for AlphanumericRule
Source§impl Default for AlphanumericRule
impl Default for AlphanumericRule
Source§fn default() -> AlphanumericRule
fn default() -> AlphanumericRule
Returns the “default value” for a type. Read more
Source§impl Rule<String> for AlphanumericRule
impl Rule<String> for AlphanumericRule
Source§fn validate(
&self,
value: &String,
ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &String, ctx: &ValidationContext, ) -> ValidationResult<()>
Validate the value.
Source§fn default_message(&self) -> String
fn default_message(&self) -> String
Get the default error message.
Source§fn validate_at(
&self,
value: &T,
path: &FieldPath,
ctx: &ValidationContext,
) -> Result<(), ValidationErrors>
fn validate_at( &self, value: &T, path: &FieldPath, ctx: &ValidationContext, ) -> Result<(), ValidationErrors>
Validate the value with a field path for error reporting.
Source§fn error_code(&self) -> String
fn error_code(&self) -> String
Get the error code.
Source§fn is_transform(&self) -> bool
fn is_transform(&self) -> bool
Check if this rule is a transformation (not validation).
Source§impl Rule<str> for AlphanumericRule
impl Rule<str> for AlphanumericRule
Source§fn validate(
&self,
value: &str,
_ctx: &ValidationContext,
) -> ValidationResult<()>
fn validate( &self, value: &str, _ctx: &ValidationContext, ) -> ValidationResult<()>
Validate the value.
Source§fn default_message(&self) -> String
fn default_message(&self) -> String
Get the default error message.
Source§fn validate_at(
&self,
value: &T,
path: &FieldPath,
ctx: &ValidationContext,
) -> Result<(), ValidationErrors>
fn validate_at( &self, value: &T, path: &FieldPath, ctx: &ValidationContext, ) -> Result<(), ValidationErrors>
Validate the value with a field path for error reporting.
Source§fn error_code(&self) -> String
fn error_code(&self) -> String
Get the error code.
Source§fn is_transform(&self) -> bool
fn is_transform(&self) -> bool
Check if this rule is a transformation (not validation).
Auto Trait Implementations§
impl Freeze for AlphanumericRule
impl RefUnwindSafe for AlphanumericRule
impl Send for AlphanumericRule
impl Sync for AlphanumericRule
impl Unpin for AlphanumericRule
impl UnwindSafe for AlphanumericRule
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