UNPKG

@mehekfatima/auto-form-validator

Version:

A smart, zero-setup form validation library for React with automatic rule detection, i18n support, async validation, and UI integration helpers.

27 lines (25 loc) 804 B
import "../chunk-UJCSKKID.mjs"; // src/utils/asyncValidators.ts var createUsernameAvailableValidator = (checkFn, message) => { return async (username) => { if (!username.trim()) return null; try { const isAvailable = await checkFn(username); return isAvailable ? null : message || "Username is already taken"; } catch { return null; } }; }; var createEmailDomainValidator = (allowedDomains, message) => { return async (email) => { if (!email.includes("@")) return null; const domain = email.split("@")[1].toLowerCase(); const isAllowed = allowedDomains.some((d) => d.toLowerCase() === domain); return isAllowed ? null : message || "Email domain is not allowed"; }; }; export { createEmailDomainValidator, createUsernameAvailableValidator };