Files
motovaultpro/backend/src/shared-minimal/utils/validators.ts
Eric Gullickson f79fda79b9
All checks were successful
Deploy to Staging / Build Images (push) Successful in 4m31s
Deploy to Staging / Deploy to Staging (push) Successful in 36s
Deploy to Staging / Verify Staging (push) Successful in 5s
Deploy to Staging / Notify Staging Ready (push) Successful in 5s
Deploy to Staging / Notify Staging Failure (push) Has been skipped
fix: Short VIN Storage - Issue #1
2026-01-01 10:05:56 -06:00

38 lines
1.2 KiB
TypeScript

/**
* @ai-summary Generic validation utilities (no business logic)
* @ai-context Pure functions only, no feature-specific logic
*/
export function isValidEmail(email: string): boolean {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
export function isValidPhone(phone: string): boolean {
const phoneRegex = /^\+?[\d\s\-()]+$/;
return phoneRegex.test(phone) && phone.replace(/\D/g, '').length >= 10;
}
export function isValidUUID(uuid: string): boolean {
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
return uuidRegex.test(uuid);
}
export function isValidVIN(vin: string): boolean {
// VIN must be exactly 17 characters (modern VIN standard since 1981)
if (vin.length !== 17) return false;
// VIN cannot contain I, O, or Q
if (/[IOQ]/i.test(vin)) return false;
// Must be alphanumeric
return /^[A-HJ-NPR-Z0-9]{17}$/i.test(vin);
}
export function isValidPreModernVIN(vin: string): boolean {
// Pre-1981 vehicles had non-standardized VINs of varying lengths (1-17 characters)
if (vin.length < 1 || vin.length > 17) return false;
// Must be alphanumeric (allow I, O, Q for pre-1981 as they weren't banned yet)
return /^[A-Z0-9]+$/i.test(vin);
}