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

Validate email entry

Participant ,
Jan 13, 2024 Jan 13, 2024

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

 

TOPICS
PDF forms
1.3K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jan 13, 2024 Jan 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.");

View solution in original post

Translate
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 ,
Jan 13, 2024 Jan 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.");

Translate
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
Participant ,
Jan 13, 2024 Jan 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.

Translate
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 ,
Jan 13, 2024 Jan 13, 2024
LATEST

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.

Translate
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