Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Validate if the second date is in the same year as the first date.

Community Beginner ,
Jul 27, 2016 Jul 27, 2016

Hi.

I've created a form in which (among other things) the user has to input two dates, a start date and an end date.

From those two dates the number of weeks worked is calculated.

Screen Shot 2016-07-27 at 17.30.21.png

There is already a custom validation script in place which checks if the date is entered in the right formatting (day, month, year) and gives an error if that's not the case.

What I would like the script to do as well, is to check if the end date is in the same year as the start date.

I've found some examples of scripts that check the date, but can't figure out how to modify and add this in my own script.

This is the script thats in place now:

// JavaScript code for date mask format DD/MM/YYYY

var format = /^[mdy0-9]{2}\/[mdy0-9]{2}\/[mdy0-9]{4}$/

    var datespan = util.scand("dd/mm/yyyy", event.value);

//Allow blank space in field

if (event.value !="") {

  if (format.test(event.value) == false) {

    app.alert ({

       cTitle: "Ongeldige datum ingevuld.",

       cMsg: "De datum moet u als volgt invullen: dd/mm/jjjj."

    });

    }

}

(I've also got a document javascript and a custom keystroke script in place since this script doesn't seem to catch all the wrong date formats.)

Does anyone here have an idea how to check the second year against the first, give an error if it's not the same and how to add it to this script?

Thanks for any thoughts on this!

TOPICS
Acrobat SDK and JavaScript , Windows
396
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 27, 2016 Jul 27, 2016

Read the value of the other field, convert it to a Date object as well, and then use the getFullYear method on both of the Date objects to make sure they fall within the same calendar year. If not, reject the new value and show an error message.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 16, 2016 Aug 16, 2016

Hello try67, thanks for your answer, and sorry for the late reply. Something came up.

I understand the logic, but I'm not really sure on how to do that I'm afraid. I might get the script working on itself, but wouldn't know how to make it part of the first script. Is that something you could help me with?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2016 Aug 16, 2016
LATEST

Sure. I sent you an email regarding it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines