From ee22216bf904ea9e5cfba79d236b3c6df9943e48 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 23 Aug 2024 10:30:27 -0700 Subject: [PATCH] Add custom validator to check for lowercase --- Client/src/Validation/validation.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Client/src/Validation/validation.js b/Client/src/Validation/validation.js index ab2501199..35d47d6b1 100644 --- a/Client/src/Validation/validation.js +++ b/Client/src/Validation/validation.js @@ -49,6 +49,13 @@ const credentials = joi.object({ .string() .trim() .email({ tlds: { allow: false } }) + .custom((value, helpers) => { + const lowercasedValue = value.toLowerCase(); + if (value !== lowercasedValue) { + return helpers.message("Email must be in lowercase"); + } + return lowercasedValue; + }) .messages({ "string.empty": "Email is required", "string.email": "Must be a valid email address", @@ -72,14 +79,10 @@ const credentials = joi.object({ }); const monitorValidation = joi.object({ - url: joi - .string() - .uri({ allowRelative: true }) - .trim() - .messages({ - "string.empty": "This field is required.", - "string.uri": "The URL you provided is not valid.", - }), + url: joi.string().uri({ allowRelative: true }).trim().messages({ + "string.empty": "This field is required.", + "string.uri": "The URL you provided is not valid.", + }), name: joi.string().trim().max(50).allow("").messages({ "string.max": "This field should not exceed the 50 characters limit.", }),