Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

How to validate a date field with reference to a year only

Cari_Jansen
Level 2
Level 2

Is there a way to set-up a date field so that it validates entering 4-digits for a Year only data entry?

I've tried setting Validation Pattern to date{YYYY}, however that throws an 'pattern is invalid' error.

Had a bit of a browse on the forum, but not been able to find a solution for this.

Thanks heaps,

Cari

1 Reply
_Bruce_Robertson
Level 10
Level 10

Hi Cari,

I don't think you can do this with the validation pattern, you would have to use some script.

Is it possible to use a drop down list, with the years as values?  You could use some code like this in the preOpen event to populate the values (which populates the last 20 years);

var d = new Date()

var years = []

for (var y = new Date(d.getFullYear() - 20, 0, 1); y.getFullYear() <= d.getFullYear(); y.setFullYear(y.getFullYear()+1)) {

    years.push(y.getFullYear());

}

this.setItems(years.join(","));

Regards

Bruce