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
String
required
The date string to validate in DD-MM-YYYY format.
Return Value
DateTime
The parsed DateTime if the string is valid.
Exceptions
FormatException
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
DateTime
required
The date to validate.
DateTime
required
The date that
date must be before.Exceptions
ArgumentError
Thrown if the date is not before the specified date.
NeoDateValidator.validateIsAfter()
Validates that a date occurs after another specified date.Parameters
DateTime
required
The date to validate.
DateTime
required
The date that
date must be after.Exceptions
ArgumentError
Thrown if the date is not after the specified date.
NeoDateValidator.validateIsInRange()
Validates that a date falls within a specified range (inclusive).Parameters
DateTime
required
The date to validate.
DateTime
required
The start of the valid range (inclusive).
DateTime
required
The end of the valid range (inclusive).
Exceptions
ArgumentError
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
DateTime
required
The date to validate.
Exceptions
ArgumentError
Thrown if the date is in the future.
NeoDateValidator.validateIsNotPast()
Validates that a date is not in the past (today or later).Parameters
DateTime
required
The date to validate.
Exceptions
ArgumentError
Thrown if the date is in the past.
NeoDateValidator.format()
Formats a DateTime object to a DD-MM-YYYY string.Parameters
DateTime
required
The DateTime object to format.
Return Value
String
The formatted date string in DD-MM-YYYY format.
Best Practices
- Handle exceptions properly: Use try-catch blocks to handle
FormatExceptionandArgumentErrorseparately - Combine validation methods: Chain multiple validations for comprehensive date checking
- Use in form callbacks: Validate in
onSubmittedcallbacks 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

