Skip to content

Hello, how can I set constant values in the text for an error? #389

@Desalutar20

Description

@Desalutar20

Is there a way to use variables in error messages?

use serde::{Deserialize, Serialize};
use validator::Validate;

use crate::features::auth::constants::{
    FIRST_NAME_MAX_LENGTH, FIRST_NAME_MIN_LENGTH, LAST_NAME_MAX_LENGTH, LAST_NAME_MIN_LENGTH,
    PASSWORD_MAX_LENGTH, PASSWORD_MIN_LENGTH,
};

#[derive(Deserialize, Serialize, Validate)]
pub struct SignUpRequest {
    #[validate(email(message = "Invalid email address format"))]
    pub email: String,

    #[validate(
           length(min = PASSWORD_MIN_LENGTH, max = PASSWORD_MAX_LENGTH, message = "Password must be between {min} and {max} characters")
       )]
    pub password: String,

    #[validate(
           length(min = FIRST_NAME_MIN_LENGTH, max = FIRST_NAME_MAX_LENGTH, message = "First name must be between {min} and {max} characters")
       )]
    pub first_name: String,

    #[validate(
          length(min = LAST_NAME_MIN_LENGTH, max = LAST_NAME_MAX_LENGTH, message = "Last name must be between {min} and {max} characters")
      )]
    pub last_name: String,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions