Overview
All validation schemas are built with Zod, a TypeScript-first schema validation library. These schemas are used with React Hook Form for client-side validation and can also validate server action payloads.Shared Validators
Reusable schema builders for common field types.getRequiredStringSchema
Creates a required string field schema.Field name for error messages
Custom error message (defaults to ” is required”)
Zod string schema with minimum length of 1
getOptionalStringSchema
Creates an optional string field schema that acceptsnull or undefined.
Zod optional nullable string schema
getRequiredEmailSchema
Creates a required email field schema with validation.Field name for error messages
Zod string schema with email validation
getRequiredNumberSchema
Creates a required number field schema.Field name for error messages
Zod number schema with minimum value of 1
getRequiredNumericStringSchema
Creates a required string schema that accepts only numeric values (with optional decimal).Field name for error messages
Zod string schema that validates numeric format
createPasswordSchema
Creates a password and confirm password validation schema.Field name for error messages
Zod object schema with
password and confirmPassword fields- Minimum 8 characters
- At least one number
- At least one uppercase letter
- At least one special character (
!@#$%^&*()) - Password and confirm password must match
getRequiredOTPSchema
Creates an OTP (One-Time Password) field schema.Field name for error messages
Zod string schema requiring 6 digits
getDigitSchema
Creates a schema for digit-only strings with minimum length.Field name for error messages
Minimum number of digits required
Zod string schema validating digits only
getFullNameSchema
Creates a schema for full names (requires first and last name).Zod string schema requiring at least two space-separated words
getValidNigerianPhoneNumber
Creates a schema for Nigerian phone numbers.Zod string schema validating Nigerian phone format
getOptionalNigerianPhoneSchema
Creates an optional Nigerian phone number schema.Zod optional string schema for Nigerian phone numbers
Authentication Schemas
Validation schemas for authentication flows.SIGN_UP_STEP_1_SCHEMA
Validates user information and password in the sign-up flow.user.first_name- Requireduser.last_name- Requireduser.email- Required, valid email formatpassword- Required, minimum 8 characters, must contain:- At least one number
- At least one uppercase letter
- At least one special character (
!@#$%^&*())
SIGN_UP_STEP_2_SCHEMA
Validates organization information in the sign-up flow.organization.name- Requiredorganization.industry- Requiredorganization.team_strength- Required
SIGN_UP_FULL_SCHEMA
Complete sign-up validation schema combining both steps.Asset Schemas
Validation schemas for asset management.ADD_ASSET_SCHEMA
Validates asset creation and updates.name- Asset nametag- Unique asset tagparent_site.id- Site IDtype- Asset type (fromASSET_TYPE_OPTIONS)model_number- Model numberserial_number- Serial numbercriticality_level- Criticality leveloperating_hours- Operating hourscommissioned_date- Commission datestatus- Operational statusmaintenance_strategy- Maintenance strategylast_performed_maintenance- Last maintenance datemajor_overhaul- Major overhaul datelast_date_overhaul- Last overhaul dateassignee.id- Assigned user IDpower_rating- Power rating in kWspeed- Speed in RPMcapacity- Capacity in m³/h
equipment_class- Equipment classificationmanufacturer- Manufacturer nameis_modified- Boolean flagdatasheet- Object withfile_url,file_name,uploaded_at
Sample Schemas
Validation schemas for oil sample reports.ADD_SAMPLE_SCHEMA
Validates sample creation.site.id- Site IDasset.id- Asset IDsampling_point.id- Sampling point IDserial_number- Sample serial numberdate_sampled- Sample date (timestamp)lab_name- Laboratory nameservice_meter_reading- Numeric stringhrs- Operating hoursoil_in_service- Numeric stringfilter_changed- Yes/Nooil_drained- Yes/Noseverity- Severity level
wear_metals- Record of metal types to valuescontaminants- Array of{ type, value, unit }particle_counts- Array of{ size_range, count, unit }viscosity_levels- Array of{ temperature, viscosity, unit }additives- Record or array of additivescollection_date- Collection date stringdocument_url- Attachment URL
EDIT_SAMPLE_SCHEMA
Validates sample updates (same structure asADD_SAMPLE_SCHEMA without document_url).
Other Entity Schemas
Additional schemas are available for:- Alarms -
ADD_ALARM_SCHEMA,EDIT_ALARM_SCHEMA - Recommendations -
ADD_RECOMMENDATION_SCHEMA,EDIT_RECOMMENDATION_SCHEMA - Organizations -
ADD_ORGANIZATION_SCHEMA,EDIT_ORGANIZATION_SCHEMA - Sites -
ADD_SITE_SCHEMA,EDIT_SITE_SCHEMA - Departments -
ADD_DEPARTMENT_SCHEMA,EDIT_DEPARTMENT_SCHEMA - Users -
CREATE_USER_SCHEMA,EDIT_USER_SCHEMA - Roles -
CREATE_ROLE_SCHEMA,EDIT_ROLE_SCHEMA - Sampling Points -
ADD_SAMPLING_POINT_SCHEMA,EDIT_SAMPLING_POINT_SCHEMA - Sampling Routes -
ADD_SAMPLING_ROUTE_SCHEMA,EDIT_SAMPLING_ROUTE_SCHEMA
@/schema.
Type Inference
Zod schemas automatically generate TypeScript types:Best Practices
Client and Server Validation: Always validate on the client with React Hook Form and Zod, then re-validate on the server in server actions to ensure data integrity.
Custom Error Messages: Use the
label parameter in schema builders to provide user-friendly error messages that match your UI field labels.Type Safety: Use
z.infer<typeof SCHEMA> to generate TypeScript types from schemas. This ensures your types stay in sync with validation rules.Numeric Strings: Use
getRequiredNumericStringSchema() for inputs that must be numeric but are stored as strings (common with form inputs). This prevents validation errors from string-number type mismatches.Related Resources
- Forms & Validation Guide - Practical guide to form handling
- Server Actions - Using validated data in server actions
- Type Definitions - Entity type definitions
- Zod Documentation - Official Zod documentation