~/workspace/source/utils/validation.js.
Date Validation
Date validation ensures that reservations have valid check-in and check-out dates according to business rules.Check-in Date Rules
Must be today or a future date (cannot be in the past)
validation.js:16-19
The system uses the Temporal API for date handling, which provides more accurate date comparisons than traditional Date objects.
Check-out Date Rules
Must be after the check-in date
validation.js:56-58
Date Range Validation
Implementation:validation.js:6-11
- Check-in is not in the past
- Check-out is after check-in
Night Limit Validation
Must be between 1 and 14 nights
validation.js:92-95
Date Validation Error Messages
Date Validation Error Messages
| Condition | Error Message |
|---|---|
| Check-in in the past | ”El rango de fechas no es válido.” |
| Check-out before check-in | ”El rango de fechas no es válido.” |
| More than 14 nights | ”Solo se puede reservar hasta 14 noches.” |
Guest Data Validation
All guest information must pass validation before a reservation can be created. Guest data is validated using regex patterns.Email Validation
Must match standard email format
validation.js:116
^[a-zA-Z0-9._-]+- Starts with alphanumeric characters, dots, underscores, or hyphens@- Required @ symbol[a-zA-Z0-9.-]+- Domain name with alphanumeric, dots, or hyphens\.- Required dot before TLD[a-zA-Z]{2,}$- Top-level domain (minimum 2 letters)
invalid.email(missing @)@domain.com(missing local part)user@domain(missing TLD)
DNI Validation
Must match Spanish DNI format (1-8 digits followed by a letter)
validation.js:122
^\d{1,8}- Starts with 1 to 8 digits[A-Za-z]$- Ends with a single letter (uppercase or lowercase)
12345678A1234567B87654321b(lowercase accepted)
123456789A(too many digits)12345678(missing letter)A12345678(letter at wrong position)
The DNI validation only checks the format, not the validity of the check letter. A full DNI validation would verify that the letter matches the DNI number using the modulo-23 algorithm.
Phone Validation
Must match international or national phone format
validation.js:127
^(\+?\d{1,3})?- Optional country code (+ followed by 1-3 digits)[\s.-]?- Optional separator (space, dot, or hyphen)\d{9}$- Exactly 9 digits for the phone number
+34 612345678612345678+1.555123456(note: this passes but may not be a valid US format)+34-612345678
+34 12345(not enough digits)12345678(only 8 digits)++34 612345678(double plus sign)
Guest Validation Function
Implementation:validation.js:107-113
Guest Validation Error
Guest Validation Error
If any guest field is invalid, the reservation validation returns:
Room Availability Validation
Before creating a reservation, the system validates that the requested room exists and is available.Room Existence
Room number must exist in the hotel’s room inventory
validation.js:75-80
Room Availability
Room must not have conflicting reservations for the requested dates
validation.js:82-87
A room is considered unavailable if there’s any reservation that overlaps with the requested dates, regardless of reservation status (confirmed, checked-in, or occupied).
Date Range Overlap
The availability check determines if two date ranges overlap: Overlap occurs when:- Existing reservation’s check-in falls within the requested dates, OR
- Existing reservation’s check-out falls within the requested dates, OR
- Requested dates fall entirely within an existing reservation
- Requested check-in equals existing check-out (same-day turnover allowed)
- Requested check-out equals existing check-in (same-day turnover allowed)
Complete Reservation Validation
ThevalidateReservation() function performs all validations before creating a reservation.
Implementation: validation.js:63-102
Validation Order
Validations are performed in this sequence:- Room existence - Check if room number is valid
- Room availability - Check if room is free for the dates
- Date range - Check if dates are valid (not in past, check-out after check-in)
- Night limit - Check if stay is between 1-14 nights
- Guest data - Validate email, DNI, and phone
Validation Response
The function returns an object with validation status:Summary of All Validation Rules
Summary of All Validation Rules
| Category | Rule | Error Message |
|---|---|---|
| Room | Room must exist | ”La habitación número no existe.” |
| Room | Room must be available | ”La habitación número está reservada para esas fechas.” |
| Dates | Check-in not in past | ”El rango de fechas no es válido.” |
| Dates | Check-out after check-in | ”El rango de fechas no es válido.” |
| Dates | Maximum 14 nights | ”Solo se puede reservar hasta 14 noches.” |
| Guest | Valid email format | ”Los datos del huesped no son válidos” |
| Guest | Valid DNI format | ”Los datos del huesped no son válidos” |
| Guest | Valid phone format | ”Los datos del huesped no son válidos” |