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

Text Field Validation within a date range

Community Beginner ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

Is it possibly in a Text Field with date format, if someone enters a date outisde of a range you specify to pop up an error message?

TOPICS
Create PDFs , How to , JavaScript , PDF forms

Views

395

Translate

Translate

Report

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 ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

Yes, it is possible. 

Votes

Translate

Translate

Report

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 ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

Here's an example of a custom validation script that does it:

 

var startDateString =  "01/01/2022";
var endDateString =  "07/01/2022";
var startDate = util.scand("mm/dd/yyyy", startDateString);
var endDate = util.scand("mm/dd/yyyy", endDateString);

if (event.value) {
	var d = util.scand("mm/dd/yyyy", event.value);
	if (d.getTime()<startDate.getTime() || d.getTime()>endDate.getTime()) {
		app.alert("Error! The entered date must be between " + startDateString + " and " + endDateString);
		event.rc = false;
	}
}

Votes

Translate

Translate

Report

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 ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much.  Exactly what I needed.

Votes

Translate

Translate

Report

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 ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

You can turn both date to seconds and then compare them, something like this:

var date1 = util.scand("mm/dd/yyyy", event.value);
var date2 = util.scand("mm/dd/yyyy", "07/01/2022");

var sec1 = date1.getTime() / 1000;
var sec2 = date2.getTime() / 1000;
if(event.value && sec1 > sec2){
app.alert("Message goes here");
event.rc = false;}

Use it as validation script of date field.

Set which date you want in variable date2 (I used 07/01/2022)

Votes

Translate

Translate

Report

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