Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

715 B
Raw Blame
import { useTranslation } from "@/i18n/client";

/**
 * @deprecated Use form validation hook instead
 */
export const requiredString = (value: string) => !!value.trim();

const emailRegex = /^[^@\s]+@[^@\s]+\.[^@\s]+$/;

export const useFormValidation = () => {
  const { t } = useTranslation();

  return {
    requiredString: (name?: string) => (value: string) => {
      if (!value || !value.trim()) {
        return t("requiredString", {
          name,
          defaultValue: "“{name}” is required",
        });
      }
    },

    validEmail: (value: string) => {
      if (!emailRegex.test(value)) {
        return t("validEmail", { defaultValue: "Please enter a valid email" });
      }
    },
  };
};