Files
Inventory/frontend/app/shared/validation/email.ts
Matthieu 974a4a0781 refactor : merge Inventory_frontend submodule into frontend/ directory
Merges the full git history of Inventory_frontend into the monorepo
under frontend/. Removes the submodule in favor of a unified repo.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:17:57 +02:00

35 lines
904 B
TypeScript

import { normalizeEmail } from '~/utils/formatters/email'
const EMAIL_VALIDATION_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
export const EMAIL_INPUT_PATTERN = EMAIL_VALIDATION_PATTERN.source
export type EmailValidationResult = {
valid: boolean
error?: string
}
export const EMAIL_VALIDATION_ERROR = 'Adresse email invalide'
/**
* Minimal email schema to align validation logic across the UI.
*/
export const emailSchema = {
pattern: EMAIL_VALIDATION_PATTERN,
message: EMAIL_VALIDATION_ERROR,
validate(value: string): EmailValidationResult {
const normalized = normalizeEmail(value)
if (!normalized) {
return { valid: true }
}
if (EMAIL_VALIDATION_PATTERN.test(normalized)) {
return { valid: true }
}
return { valid: false, error: EMAIL_VALIDATION_ERROR }
},
}
export const isEmailValid = (value: string): boolean => emailSchema.validate(value).valid