Skip to main content

Examples

  • Basic Validation
  • Date Formatting
  • Form Integration
DateTime date = NeoDateValidator.validate("31-10-2024");

Methods

NeoDateValidator.validate()

Validates and parses a date string in DD-MM-YYYY format with comprehensive error checking.

Parameters

dateString
String
required
The date string to validate in DD-MM-YYYY format.

Return Value

returns
DateTime
The parsed DateTime if the string is valid.

Exceptions

throws
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

date
DateTime
required
The date to validate.
beforeDate
DateTime
required
The date that date must be before.

Exceptions

throws
ArgumentError
Thrown if the date is not before the specified date.

NeoDateValidator.validateIsAfter()

Validates that a date occurs after another specified date.

Parameters

date
DateTime
required
The date to validate.
afterDate
DateTime
required
The date that date must be after.

Exceptions

throws
ArgumentError
Thrown if the date is not after the specified date.

NeoDateValidator.validateIsInRange()

Validates that a date falls within a specified range (inclusive).

Parameters

date
DateTime
required
The date to validate.
startDate
DateTime
required
The start of the valid range (inclusive).
endDate
DateTime
required
The end of the valid range (inclusive).

Exceptions

throws
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

date
DateTime
required
The date to validate.

Exceptions

throws
ArgumentError
Thrown if the date is in the future.

NeoDateValidator.validateIsNotPast()

Validates that a date is not in the past (today or later).

Parameters

date
DateTime
required
The date to validate.

Exceptions

throws
ArgumentError
Thrown if the date is in the past.

NeoDateValidator.format()

Formats a DateTime object to a DD-MM-YYYY string.

Parameters

date
DateTime
required
The DateTime object to format.

Return Value

returns
String
The formatted date string in DD-MM-YYYY format.

Best Practices

  • Handle exceptions properly: Use try-catch blocks to handle FormatException and ArgumentError 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
I