From 2ac220b6e389f3284336d5dfb9c4c89bf487c44f Mon Sep 17 00:00:00 2001 From: dsiguero <26867647+dsiguero@users.noreply.github.com> Date: Mon, 12 May 2025 01:08:02 +0200 Subject: [PATCH] feat: add schema for SMS (body or field) --- src/schemas/sms.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/schemas/sms.ts diff --git a/src/schemas/sms.ts b/src/schemas/sms.ts new file mode 100644 index 0000000..94bff0a --- /dev/null +++ b/src/schemas/sms.ts @@ -0,0 +1,18 @@ +import { z } from 'zod'; + +export const SMS_CHARACTER_REGEX = /^[a-zA-Z0-9\s.,!?'"():;\-_]*$/; +export const SMS_CHARACTER_LIMIT = 160; + +type SmsValidationMessages = Partial<{ + invalidType: string; + regex: string; +}>; + +const zodMessageOrUndefined = (message?: string): { message: string } | undefined => { + return message ? { message: message } : undefined; +}; + +export const createSmsContentSchema = (messages: SmsValidationMessages = {}): z.ZodString => + z + .string(zodMessageOrUndefined(messages.invalidType)) + .regex(SMS_CHARACTER_REGEX, zodMessageOrUndefined(messages.regex));