Skip to main content

Overview

Simple Manager Mobile implements validation rules to ensure data integrity and provide a good user experience. Validation occurs before records are saved to the database.

Validation Interface

The validation system uses a simple result interface:
export interface ValidationResult {
    valid: boolean;
    message?: string;
}
valid
boolean
required
Indicates whether the validation passed (true) or failed (false).
message
string
Error message in Spanish explaining why validation failed. Only present when valid is false.

Record Validation Function

The validateRecord function validates record title and type fields:
export function validateRecord(title: string, type: string): ValidationResult {
    const cleanTitle = title.trim();
    const cleanType = type.trim();

    if (!cleanTitle || !cleanType) {
        return { valid: false, message: "Todos los campos son obligatorios" };
    }

    if (cleanTitle.length < 3) {
        return { valid: false, message: "El título debe tener al menos 3 caracteres" };
    }

    if (cleanTitle.length > 50) {
        return { valid: false, message: "El título no puede superar los 50 caracteres" };
    }

    if (cleanType.length < 3) {
        return { valid: false, message: "El tipo debe tener al menos 3 caracteres" };
    }

    return { valid: true };
}

Validation Rules

Title Validation

Required
rule
The title field cannot be empty or contain only whitespace.Error message: “Todos los campos son obligatorios”
Minimum Length
rule
Title must be at least 3 characters long (after trimming whitespace).Error message: “El título debe tener al menos 3 caracteres”
Maximum Length
rule
Title cannot exceed 50 characters (after trimming whitespace).Error message: “El título no puede superar los 50 caracteres”
Uniqueness
rule
Titles cannot be duplicated within the database (enforced at database level).

Type Validation

Required
rule
The type field cannot be empty or contain only whitespace.Error message: “Todos los campos son obligatorios”
Minimum Length
rule
Type must be at least 3 characters long (after trimming whitespace).Error message: “El tipo debe tener al menos 3 caracteres”

Usage Example

import { validateRecord } from './validators/recordValidator';

const result = validateRecord("My Record", "task");

if (result.valid) {
    // Proceed with saving the record
    console.log("Validation passed");
} else {
    // Display error message to user
    console.error(result.message);
}

Error Handling

All validation error messages are in Spanish to match the application’s target audience:
Validation ErrorSpanish Message
Empty fields”Todos los campos son obligatorios”
Title too short”El título debe tener al menos 3 caracteres”
Title too long”El título no puede superar los 50 caracteres”
Type too short”El tipo debe tener al menos 3 caracteres”

Best Practices

  1. Always trim input: The validator trims whitespace before checking length
  2. Check early: Validate before attempting database operations
  3. Show clear errors: Display the validation message to users
  4. Client-side only: Current validation runs on the client; consider adding server-side validation for multi-user scenarios

Build docs developers (and LLMs) love