Overview
The validator module provides comprehensive validation for all QR data types. Each validator returns aValidationResult object containing validation status and detailed error messages.
ValidationResult Interface
true if all validations pass, false if any validation failsObject mapping field names to error messages. Empty object when
isValid is trueMain Validator
validateQrData
Main validation function that routes to the appropriate validator based on QR type.The QR code type identifier
The data object to validate. Returns invalid if
nullValidation result with
isValid flag and any error messagesExample
Type-Specific Validators
validateTextQr
Validates plain text QR data.Text data to validate
Validation Rules
- text: Required, non-empty after trimming
- text: Minimum 1 character
- text: Maximum 2953 characters
Example
validateUrlQr
Validates URL QR data.URL data to validate
Validation Rules
- url: Required, non-empty after trimming
- url: Must be a valid URL format (checked with URL constructor)
- url: Protocol (http:// or https://) is optional for validation
Example
validateWifiQr
Validates WiFi network QR data.WiFi data to validate
Validation Rules
- ssid: Required, non-empty after trimming
- ssid: Maximum 32 characters
- password: Required if security is not
"nopass" - password: Minimum 5 characters for WEP
- password: Minimum 8 characters for WPA
- password: Maximum 63 characters
Example
validateVCardQr
Validates vCard contact QR data.vCard data to validate
Validation Rules
- firstName: Required, non-empty after trimming
- lastName: Required, non-empty after trimming
- phone: Optional, but must match phone format if provided (7+ chars, digits/spaces/+/-/())
- mobile: Optional, but must match phone format if provided
- email: Optional, but must match email format if provided (basic regex:
[^\ s@]+@[^\ s@]+\.[^\ s@]+) - website: Optional, but must be valid URL if provided
Example
validatePaymentQr
Validates payment QR data.Payment data to validate
Validation Rules
- method: Required, non-empty after trimming
- name: Required, non-empty after trimming
- account: Required, non-empty after trimming
- account: If method is
"crypto", minimum 26 characters - account: If method is not crypto, must contain only digits, hyphens, and spaces
- bank: Required, non-empty after trimming
- amount: Must be greater than 0
- amount: Must be a valid number (not NaN)
Example
validateEventQr
Validates calendar event QR data.Event data to validate
Validation Rules
- title: Required, non-empty after trimming
- location: Required, non-empty after trimming
- start: Required, non-empty after trimming
- start: Must be a valid date string
- end: Required, non-empty after trimming
- end: Must be a valid date string
- end: Must be after start time
Example
Helper Functions
isValidUrl
Internal helper to validate URL format.https:// if no protocol is present before validation.
isValidEmail
Internal helper to validate email format./^[^\s@]+@[^\s@]+\.[^\s@]+$/
isValidPhone
Internal helper to validate phone number format.- Minimum 7 characters
- Contains only digits, spaces, hyphens, plus signs, and parentheses
- Uses regex:
/^[\d\s\-\+\(\)]+$/
Error Messages
All error messages are in Spanish. Common messages include:"El {campo} es obligatorio"- Required field is empty"{Campo} inválido"- Invalid format"La contraseña WPA/WPA2 debe tener al menos 8 caracteres"- WPA password too short"El monto debe ser mayor a 0"- Amount must be positive"La fecha de fin debe ser posterior a la de inicio"- End date before start date