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

Dynamic Email Button, problem with invalid email - Please help!

Engaged ,
Jun 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

I’m having a problem setting up my dynamic email button.  It works fine if I use an email address without dashes (eg. smitht@dsv.org), but when I use the email addresses as shown below with a dash I get an ‘Invalid Email’ Warning.   I don’t know how to set it up as that is how the emails are supposed to be and I don’t know how to resolve it.  I have documented the script I have.  Any help would be appreciated.  Thank you!!

 

//Submit button Actions Run a Script

if(ValidFields())

{

   var cToAddr = this.getField("ForemanEmail").value;

   // Set the subject line

   var cSubLine = "eDAC "

                + this.getField("Date").value + " "

                                                                + this.getField("CrewName").value;

   var cBody = "Thank you for submitting your timesheet.\n" +

               "Please save a copy for your records";

   this.mailDoc({bUI:true, cTo: cToAddr, cSubject: cSubLine,

                  cMsg: cBody});

}

 

//ForemanEmail Text Field Custom Keystroke Script

var rxp = /^\s*(\w+(\.\w+)*@(\w+\.)+\w{2,3})\s*$/;

 

if(event.willCommit && (event.value != "") )

{

  if(event.rc =  rxp.test(event.value))

     event.value = RegExp.$1

  else

     app.alert("Invalid Email",1);

}

 

//Document JavaScript Submit Button

function ValidFields()

{

   var bRtn = false;

   var aErrMsg = [];

   var rgEmpty = /^\s*$/;

   if(rgEmpty.test(this.getField("Date").value))

      aErrMsg.push("Work Date Field");

   if(rgEmpty.test(this.getField("CrewName").value))

      aErrMsg.push("Crew Name");

   if(rgEmpty.test(this.getField("ForemanEmail").value))

      aErrMsg.push(" ");

  

   if(aErrMsg.length == 0)

      bRtn = true;

   else

      app.alert("Error\nOne or more required fields have not been filled out:\n\n   * " + aErrMsg.join("\n   * "));;

 

 

   return bRtn;

}

 

//Document Javascript Init

this.getField("general_document_date_today").value = new Date();

 

//Document JavaScript populate data from Crew dropdown list to ForemanEmail and CrewName text fields

var EmailData = { "Maintenance":{ Email: "Roads-Concrete-2@dsv.org",

                              CrewName: "Maintenance" },

                 "Concrete":{ Email: "Roads-Maint-Foreman@dsv.org",

                              CrewName: "Concrete" },

                 "Asphalt" :{ Email: "Roads-Concrete-Foreman@dsv.org",

                              CrewName: "Asphalt" }};

function SetFieldValuesEmail(cEmailName)

{

  this.getField("ForemanEmail").value = EmailData[cEmailName].Email;

  this.getField("CrewName").value = EmailData[cEmailName].CrewName;

}

 

//Crew dropdown text field Custom Keystroke to populate data to ForemanEmail and CrewName text fields

if( event.willCommit )

{

   if(event.value == " ")

     this.resetForm(["ForemanEmail","CrewName"]);

   else    

                 SetFieldValuesEmail(event.value);

}

 

TOPICS
Acrobat SDK and JavaScript

Views

467

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 05, 2020 Jun 05, 2020

Copy link to clipboard

Copied

I would drop the email address validation entirely. If the email address is incorrect they will get an error message from their email client or server.

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 06, 2020 Jun 06, 2020

Copy link to clipboard

Copied

there are a lot of ways to write a regular expresion for email validation.

Here is the search results on a regular expression library site:

http://regexlib.com/Search.aspx?k=email&c=-1&m=-1&ps=20

 

Here's one that is covers just about everything.

^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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
Engaged ,
Jun 22, 2020 Jun 22, 2020

Copy link to clipboard

Copied

LATEST

Thank you both very much!  I'm just seeing you're replies now.  I did delete the email address validation and now it works, yeah!!

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