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

Form field validation script - report error if fields are filled with identical numbers

New Here ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

Hello

 

I have a form where customers needs to fill different information, among other they need to enter animal ID numbers into seperate fields, which then creates a barcode for each animal ID number. 

I have problems with some customers, probably when they are filling the form to quickly without double checking what they enter into the fields, sometimes they enter the same animal ID number twice (in two different fields), which creates a problem on my end when registering the order. I have 50 fields in total where animal ID numbers can be entered.

 

Is there a way to make a custom validation script, so that the 50 fields are linked to each other, and a red warning balloon is displayed if the animal ID number in one field is identical to the animal ID number in any of the other 50 fields? And then apply this validation rule to all 50 fields of course. 

 

Also, each animal ID number should be 11 characters long, nothing more nothing less, and only numbers (0-9) should be allowed as characters in these 50 fields. No letters, special characters or other should be allowed in the 50 fields. 

 

How can I do this? 

TOPICS
How to , JavaScript , PDF forms

Views

314

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

correct answers 1 Correct answer

Community Expert , May 20, 2022 May 20, 2022

Let's say the fields are named ID1 to ID50. Just saw your reply above... Place the following code as a doc-level script (via Tools - JavaScript - Document JavaScripts, under a new item called "scripts"):

 

 

function validateAnimalID() {
	if (event.value) {
		if (/^\d{11}$/.test(event.value)==false) {
			app.alert("Error! The ID must be 11-digits long.");
			event.rc = false;
			return;
		}
		for (var i=1; i<=50; i++) {
			var fname = "CKR_"+i;
			if (fname==event.target.name) continue;
			if (t
...

Votes

Translate

Translate
Community Expert ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

All of this can be achieved using a custom Validation script, but the "red warning balloon" part is trickier. An easier solution is to display an error message and reject the entered value. What are the names of the fields in question?

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
New Here ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

the warning balloon is not important, I actually just got that from this page (https://helpx.adobe.com/sign/using/form-field-validations.html) and thought it was the only option. Any error message and/or rejection of the entered value will do just fine 🙂 

 

The names of the fields are CKR_1, CKR_2, CKR_3 (...) CKR_50 

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 ,
May 20, 2022 May 20, 2022

Copy link to clipboard

Copied

Let's say the fields are named ID1 to ID50. Just saw your reply above... Place the following code as a doc-level script (via Tools - JavaScript - Document JavaScripts, under a new item called "scripts"):

 

 

function validateAnimalID() {
	if (event.value) {
		if (/^\d{11}$/.test(event.value)==false) {
			app.alert("Error! The ID must be 11-digits long.");
			event.rc = false;
			return;
		}
		for (var i=1; i<=50; i++) {
			var fname = "CKR_"+i;
			if (fname==event.target.name) continue;
			if (this.getField(fname).valueAsString==event.value) {
				app.alert("Error! The ID must be unique.");
				event.rc = false;
				return;
			}
		}
	}
}

 

 

Now open the JS Console, paste the following code into it, select it with the mouse and press Ctrl+Enter:

 

for (var i=1; i<=50; i++) this.getField("CKR_"+i).setAction("Validate", "validateAnimalID();");

 

 

Save the file and you're all set!

 

Edited: Code adjusted to use real field names...

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
New Here ,
May 24, 2022 May 24, 2022

Copy link to clipboard

Copied

LATEST

Thank you so much 🙂 

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