Skip to main content
Inspiring
June 5, 2020
Question

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

  • June 5, 2020
  • 3 replies
  • 965 views

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);

}

 

This topic has been closed for replies.

3 replies

Inspiring
June 22, 2020

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!!

Thom Parker
Community Expert
Community Expert
June 6, 2020

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 PDFScriptingUse the Acrobat JavaScript Reference early and often
try67
Community Expert
Community Expert
June 5, 2020

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.