Skip to content

Commit

Permalink
✨ feat(validations): add slug regex validation
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Feb 6, 2024
1 parent 1221142 commit b893fc0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/shared/validations/validations-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,16 @@ export const ENTITY_VALIDATION_CONFIG: Record<
implementation: handleValidation(matches, "pattern"),
},
};

const LOWERCASE_NUMBERS_HYPEN_AND_UNDERSCORE_REGEX = (delimeter: "-" | "_") =>
`^[a-z0-9${delimeter}]+$`;

export const SLUG_VALIDATION = (delimiter: "hyphens" | "underscores") => ({
validationType: "regex" as const,
constraint: {
pattern: LOWERCASE_NUMBERS_HYPEN_AND_UNDERSCORE_REGEX(
delimiter === "hyphens" ? "-" : "_"
),
},
errorMessage: `Only lowercase letters, numbers and ${delimiter} are allowed`,
});

0 comments on commit b893fc0

Please sign in to comment.