#[SOLVED] how to validate DateInput

2 messages · Page 1 of 1 (latest)

trail kiln
#

I have the following rule:

birthday: !/^\d{2}\/\d{2}\/\d{4}$/.test(
            new Date(values.birthday).toLocaleDateString('en-US')
          )
            ? 'Birthday must be in the format MM/DD/YYYY'
            : null,

For a standard DateInput (I am not extending the custom parser with dayjs). However that validation rule does not work, why? How do you properly check the input is a correct DateValue?

#

Solved:

          birthday: !/^\d{2}\/\d{2}\/\d{4}$/.test(
            new Date(values.birthday).toLocaleDateString('en-US', {
              year: 'numeric',
              month: '2-digit',
              day: '2-digit',
            })
          )
            ? 'Birthday must be in the format MM/DD/YYYY'
            : null,