/** * @module ValidationRules * Form validation rules for use with FormValidator. * Provides declarative validation through decorators. * * Validation messages use the i18n system. Load the 'r-validation' namespace * for localized error messages: * * @example * await loadNamespace('r-validation'); * * @example * // In HTML, use validation attributes * */ /** * Context provided to validators during validation. */ export interface ValidationContext { /** The HTML input type (text, number, email, etc.) */ inputType: string; /** The data-type attribute value if present */ dataType?: string; /** Adds an error message to the validation result */ addError(message: string): void; } /** * Interface for custom validators. */ interface Validator { /** * Validates the given value. * @param value - The string value to validate * @param context - Validation context with type info and error reporting */ validate(value: string, context: ValidationContext): void; } interface ValidatorRegistryEntry { validator: { new (): Validator; }; validInputTypes: string[]; } /** * Decorator to register a validator class for a specific validation name. * * @param validationName - The name used in data-validate attribute * @param validInputTypes - Optional list of input types this validator applies to * * @example * @RegisterValidator('email') * class EmailValidation implements Validator { * validate(value: string, context: ValidationContext) { * if (!value.includes('@')) { * context.addError('Invalid email address'); * } * } * } */ export declare function RegisterValidator(validationName: string, validInputTypes?: string[]): (target: { new (...args: unknown[]): Validator; }) => void; /** * Looks up a registered validator by name. * * @param name - The validator name used in `data-validate` * @returns The registry entry, or `undefined` if not found */ export declare function getValidator(name: string): ValidatorRegistryEntry | undefined; /** * Validates that a field has a non-empty value. * Use with `data-validate="required"`. */ export declare class RequiredValidation implements Validator { static create(rule: string): RequiredValidation | null; validate(value: string, context: ValidationContext): void; getMessage(): string; } /** * Validates that a numeric value falls within a specified range. * Use with `data-validate="range(min-max)"`. * * @example * */ export declare class RangeValidation implements Validator { min: number; max: number; constructor(min: number, max: number); static create(rule: string): RangeValidation | null; validate(value: string, context: ValidationContext): void; getMessage(actual: string): string; } /** * Validates that a value contains only numeric digits (0-9). * Use with `data-validate="digits"`. */ export declare class DigitsValidation implements Validator { static create(rule: string): DigitsValidation | null; validate(value: string, context: ValidationContext): void; getMessage(): string; } export {};