Checking the date field

Dear All

I need to validate the “NOT REQUIRED DATE FIELD” for the correct input format. If the user enters letters or a date in the date field in the wrong format, the user should get an error asking them to use a selection from the calendar. But also the user should be able to leave the field blank. I have tried the following options but it doesn't work for an empty field, I can't leave the field blank.
There is no problem with checking the input format, there is a problem with leaving the field blank.

Example 1
fd.field('CustomerContractDate').validators.push({
name: 'MyCustomValidator',
error: '!!!!!!!!',
validate: function(value) {
if (fd.field('CustomerContractDate').value == null && fd.validators.length == 0) {
this.error = 'Use the selection or enter manually (dd.mm.yyyy)';
return false;
}
return true;
}
});

Example 2

fd.field('WarrantyStart').addValidator({
name: 'WarrantyStart validator',
error: 'Warranty From is in incorrect format. Please, use DatePicker',
validate: function(value) {
return !isNaN(Date.parse(value));
}
});

Example 3
fd.field('DatePickerField').addValidator({
name: 'DatePickerValidator',
error: "Please use the date picker to select a date.",
validate: function(value) {
if (!value) {
return false;
}
return true;
}
});

Example 4
// Set the date format to 'dd.MM.yyyy'
datePickerField.dateFormat = 'dd.MM.yyyy';

fd.field('CustomerContractDate').validators.push({
name: 'DatePickerValidator',
error: "Please use the date picker to select a date.",
validate: function() {

    // Check if the value was manually entered (not selected from the date picker)
     if (CustomerContractDate.value && !CustomerContractDate.control().isDateSelected())
    
     {
    return true;
    }
    return false;
}

});

Hi @boiarynov,

I'm afraid this isn't possible at the moment, since the field is considered filled in only if the input is correctly formatted. I suggest making the date field required and adding a "No date" toggle to the form that would disable the date field and make it not required.

Thanks for the reply. Then what are the options to check fields for incorrect data entry? As far as I understand this behavior is caused by the editor, in the original Share Point the field can be checked.

Is there any possibility to restrict manual data entry so that the user only uses date picker?
And most importantly, not making the field mandatory.

Please explain to me why the date field works so strangely. Even if I use this code but I don't change anything in the field, just when I open the form, I still see “test”. as if the field is changed when I open the form and when I save the form even if I haven't touched the field.

fd.spRendered(function () {

fd.field('Date1').$on('change', function(value) {
alert("test")
});
});

I'm confused as to how this works and what I'm doing wrong.