Skip to main content
Known Participant
October 28, 2022
Answered

PDF forms: email address field

  • October 28, 2022
  • 2 replies
  • 4932 views

Hello,

 

I am almost happy with the javascript instructions listed below and based on Creating email address format text box formatting:

var email = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/; if (event.value!=""){if (!email.test(event.value)){event.rc = false;app.alert("\"" + event.value + "\" is not a valid email address.");};};

However, the script above does not suppress a wrong email address. It only warns about the faulty format. I would like it to be more restrictive to force right email address. How could this be achieved?

 

Thanks

Correct answer JR Boulay

You can use this as a Validation script:

 

if (event.value) {
event.rc = CBIsValidEmail(event.value);

if (!event.rc) app.alert("Invalid email address.");
}

2 replies

try67
Community Expert
Community Expert
October 29, 2022

The script above will reject an invalid email address. Where did you place it?

JR Boulay
Community Expert
Community Expert
October 29, 2022

The plutonak script also rejects some valid addresses since it does not support more than 4 characters in domain name extension.

Acrobate du PDF, InDesigner et Photoshopographe
JR Boulay
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
October 28, 2022

You can use this as a Validation script:

 

if (event.value) {
event.rc = CBIsValidEmail(event.value);

if (!event.rc) app.alert("Invalid email address.");
}

Acrobate du PDF, InDesigner et Photoshopographe
plutonakAuthor
Known Participant
November 1, 2022

ok, interesting. I have replaced my script with yours. It does something similar (even through it is probably better). It recognizes an invalid email address and issues the warning "Invalid email address" when the provided email address is invalid. However, if I clicl "ok" in the pop up window showing the warning, the faulty email address is still kept in the box and it is still possible to save the pdf with the faulty email address. If we cannot do better than that, that's ok, but I was hopping for a more restrictive approach where the faulty email address could not be saved.

try67
Community Expert
Community Expert
November 1, 2022

Then you didn't place the code in the right location. It should go under the Validation tab, in the Custom Script option.