Skip to main content
Inspiring
January 13, 2024
Answered

Validate email entry

  • January 13, 2024
  • 1 reply
  • 1896 views

When I user enters an email I need to validate the format. I'm pretty sure the answer is out here someplace, all searches return umpteen hts, but none seem to answer the simple question, how can I validate that an email entered was inthe correct form. I'm guessing that it involves a regular expressionof some sort, but I can't work it out.

Any help would be appreciated.

Jack

 

This topic has been closed for replies.
Correct answer try67

Acrobat actually has two (!) undocumented functions that do it. You can use one of them like this (as the custom validation script of the text field):

 

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

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

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 13, 2024

Acrobat actually has two (!) undocumented functions that do it. You can use one of them like this (as the custom validation script of the text field):

 

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

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

Jack157FAuthor
Inspiring
January 13, 2024

Wow! I tried it and it works. It makes me a bit edgy using an undocumented feature, but beggars can't be choosers.

Thank you.

try67
Community Expert
Community Expert
January 13, 2024

I tend to agree, although this one is not likely to be removed. But here's the source code for that method:

 

function CBIsValidEmail(addr) {
    var emailRE = /^([a-zA-Z0-9_\-\.\/]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,5}|[0-9]{1,3})(\]?)$/;
    return addr != undefined && addr != "" && addr.match(emailRE) != null;
}

 You can copy it to a doc-level script (make sure to rename it, though!) and use it on your own, without the fear of it being removed in the future. This will also help make it work in other, non-Adobe applications, as they won't have this method built-in, most likely.