Highlighted

Validate for Multiple Ranges

New Here ,
Oct 05, 2020

Copy link to clipboard

Copied

Hi,

I am trying to validate a number field. The validate range function is great, but I have two ranges that a number can fall between. I need to validate the number as being .75 or in the range from 2.25 to 6.00.

 

I have ZERO idea how to even start that custom validation script in Java. I've searched the community to see if there is something similar, but I am at a loss.

 

Any help would be appreciated. Thank you!


Scot Motzny

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use this code to do it:

 

if (event.value) {
	var v = Number(event.value);
	if ((v==0.75 || (v>=2.25 && v<=6))==false) {
		app.alert("Invalid value.");
		event.rc = false;
	}
}
TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

38

Likes

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

Validate for Multiple Ranges

New Here ,
Oct 05, 2020

Copy link to clipboard

Copied

Hi,

I am trying to validate a number field. The validate range function is great, but I have two ranges that a number can fall between. I need to validate the number as being .75 or in the range from 2.25 to 6.00.

 

I have ZERO idea how to even start that custom validation script in Java. I've searched the community to see if there is something similar, but I am at a loss.

 

Any help would be appreciated. Thank you!


Scot Motzny

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use this code to do it:

 

if (event.value) {
	var v = Number(event.value);
	if ((v==0.75 || (v>=2.25 && v<=6))==false) {
		app.alert("Invalid value.");
		event.rc = false;
	}
}
TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

39

Likes

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
Oct 05, 2020 0
Most Valuable Participant ,
Oct 05, 2020

Copy link to clipboard

Copied

You can use this code to do it:

 

if (event.value) {
	var v = Number(event.value);
	if ((v==0.75 || (v>=2.25 && v<=6))==false) {
		app.alert("Invalid value.");
		event.rc = false;
	}
}

Likes

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
Reply
Loading...
Oct 05, 2020 0
smotzny LATEST
New Here ,
Oct 06, 2020

Copy link to clipboard

Copied

Thank you so much for your help with this. That worked perfectly!

Much appreciation!

 

If you have a suggestion on where I can learn how to write Java calculations and validations I would appreciate that as well. Teach me to fish!

Likes

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
Reply
Loading...
Oct 06, 2020 0