Skip to content

Limits and validation ​

Introduction ​

Pickers check dates as people type and pick. A bad date shows a translated message under the field, and the value stays empty, so a bad date can't be submitted. Pickers never throw on bad input.

Earliest and latest dates ​

min and max are AD strings, in every picker:

tsx
<DatePicker min="2026-01-01" max="2026-12-31" />;
html
<nep-date-picker min="2026-01-01" max="2026-12-31"></nep-date-picker>

If you think in BS, convert with toIsoDate:

ts
import { bsDate, toIsoDate } from '@nepdatejs/core';

toIsoDate(bsDate(2083, 1, 1)); // → '2026-04-14'

Days outside the limits are greyed out, and the panel won't move past them.

Disabling days ​

isDateDisabled gets each date and returns true to rule it out:

tsx
import { dayOfWeek } from '@nepdatejs/core';
import { DatePicker } from '@nepdatejs/react';

const closed = new Set(['2083-07-15']);

export function Booking() {
  return (
    <DatePicker
      isDateDisabled={(date) =>
        dayOfWeek(date) === 6 || closed.has(formatDate(toCalendar(date, 'BS')))
      }
    />
  );
}

On an element, set it as a property:

js
document.querySelector('nep-date-picker').isDateDisabled = (date) => date.day === 1;

It's called for every visible day, so keep it fast. In React, the calendar redraws when its answers change, so it can depend on state.

Required fields ​

required works like it does on an <input>: an empty field stops the form from submitting.

html
<form>
  <nep-date-picker name="dob" required></nep-date-picker>
  <button>Save</button>
</form>

Errors ​

A picker's state has an error that is null, or an object with a code and a message. The message is already translated.

CodeWhenEnglish message
formatThe text isn't a dateEnter a BS date as YYYY-MM-DD.
rangeBefore min or after maxChoose 2083-06-15 or later.
disabledisDateDisabled said noThis date is not available.
tooShortRange under minDaysChoose at least 2 days.
tooLongRange over maxDaysChoose at most 15 days.
tooManyMore than maxDatesChoose at most 5 dates.

The same check in code, with the framework-free store:

ts
import { createDatePicker } from '@nepdatejs/datepicker';

const picker = createDatePicker({ min: '2026-01-01' });

picker.actions.type('hello');
picker.getState().error?.code; // → 'format'
picker.getState().value; // → ''

picker.actions.type('2083-06-24');
picker.getState().error; // → null
picker.getState().value; // → '2026-10-10'

Changing the messages ​

Messages live in the locale, so you can change them in one place.

Showing your own error ​

For a server error, pass aria-invalid and aria-describedby, and show the message yourself:

tsx
<>
  <DatePicker aria-invalid aria-describedby="date-error" />
  <p id="date-error">That day is already booked.</p>
</>;

Validating on the server ​

Client checks can be skipped, so always check again on your server. Since the value is a plain AD date, your usual tools work with no knowledge of BS. For example, in Laravel:

php
$request->validate([
    'dob' => ['required', 'date_format:Y-m-d', 'before:today'],
]);

Or in Node, with the same library:

ts
import { fromIsoDate } from '@nepdatejs/core';

function isValidDay(input: unknown) {
  return typeof input === 'string' && fromIsoDate(input) !== null;
}

isValidDay('2026-10-10'); // → true
isValidDay('2026-02-30'); // → false

Released under the MIT licence.