Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.");
Copy link to clipboard
Copied
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.");
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.