Examples
- Basic Validation
- Date Formatting
- Form Integration
Methods
NeoDateValidator.validate()
Validates and parses a date string in DD-MM-YYYY format with comprehensive error checking.Parameters
The date string to validate in DD-MM-YYYY format.
Return Value
The parsed DateTime if the string is valid.
Exceptions
Thrown with specific error messages for invalid formats, incomplete segments, or invalid dates (e.g., “Day 30 is not valid for February 2023”).
NeoDateValidator.validateIsBefore()
Validates that a date occurs before another specified date.Parameters
The date to validate.
The date that
date
must be before.Exceptions
Thrown if the date is not before the specified date.
NeoDateValidator.validateIsAfter()
Validates that a date occurs after another specified date.Parameters
The date to validate.
The date that
date
must be after.Exceptions
Thrown if the date is not after the specified date.
NeoDateValidator.validateIsInRange()
Validates that a date falls within a specified range (inclusive).Parameters
The date to validate.
The start of the valid range (inclusive).
The end of the valid range (inclusive).
Exceptions
Thrown if the date is not within the specified range.
NeoDateValidator.validateIsNotFuture()
Validates that a date is not in the future (today or earlier).Parameters
The date to validate.
Exceptions
Thrown if the date is in the future.
NeoDateValidator.validateIsNotPast()
Validates that a date is not in the past (today or later).Parameters
The date to validate.
Exceptions
Thrown if the date is in the past.
NeoDateValidator.format()
Formats a DateTime object to a DD-MM-YYYY string.Parameters
The DateTime object to format.
Return Value
The formatted date string in DD-MM-YYYY format.
Best Practices
- Handle exceptions properly: Use try-catch blocks to handle
FormatException
andArgumentError
separately - Combine validation methods: Chain multiple validations for comprehensive date checking
- Use in form callbacks: Validate in
onSubmitted
callbacks for immediate feedback - Implement business rules: Combine with custom validation logic for application-specific requirements
Integration Notes
- Detailed error messages: Provides specific error messages that can be displayed directly to users
- NeoDateField integration: Designed to work seamlessly with the string-based NeoDateField API