Add custom validator to check for lowercase

This commit is contained in:
Alex Holliday committed 2024-08-23 10:30:27 -07:00
1 parent 19f666fe82
commit ee22216bf9
1 file changed
+11 -8
+11 -8
View File
@@ -49,6 +49,13 @@ const credentials = joi.object({
.string() .string()
.trim() .trim()
.email({ tlds: { allow: false } }) .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({ .messages({
"string.empty": "Email is required", "string.empty": "Email is required",
"string.email": "Must be a valid email address", "string.email": "Must be a valid email address",
@@ -72,14 +79,10 @@ const credentials = joi.object({
}); });
const monitorValidation = joi.object({ const monitorValidation = joi.object({
url: joi url: joi.string().uri({ allowRelative: true }).trim().messages({
.string() "string.empty": "This field is required.",
.uri({ allowRelative: true }) "string.uri": "The URL you provided is not valid.",
.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({ name: joi.string().trim().max(50).allow("").messages({
"string.max": "This field should not exceed the 50 characters limit.", "string.max": "This field should not exceed the 50 characters limit.",
}), }),