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

Validating an email address with more than one domain name and eliminating the rest

Participant ,
Oct 19, 2017 Oct 19, 2017

Copy link to clipboard

Copied

I would like to validate an email address using more than one specific domain name.  My current code (which I found here) for validating an email address with one specific domain name is:

(function (){

var sDomain = "mail.mil";

if(!event.value) return;

var sEnteredDomain = event.value.split("@")[1];

if (typeof sEnteredDomain === "undefined" || sEnteredDomain.toLowerCase() !== sDomain){

event.rc = false;

app.alert("Your email address must end with:  " + sDomain, 3);

}

})();

FYI: I am using this code in a PDF form.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

444

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

correct answers 1 Correct answer

Community Expert , Oct 19, 2017 Oct 19, 2017

Try this:

(function (){

var sDomains = ["mail.mil", "mail.gov", "mail.org"];

if(!event.value) return;

var sEnteredDomain = event.value.split("@")[1];

if (typeof sEnteredDomain === "undefined" || sDomains.indexOf(sEnteredDomain.toLowerCase())==-1 ){

event.rc = false;

app.alert("Your email address must end with one of the following domains:  " + sDomains.join("\n"), 3);

}

})();

Votes

Translate

Translate
Community Expert ,
Oct 19, 2017 Oct 19, 2017

Copy link to clipboard

Copied

Try this:

(function (){

var sDomains = ["mail.mil", "mail.gov", "mail.org"];

if(!event.value) return;

var sEnteredDomain = event.value.split("@")[1];

if (typeof sEnteredDomain === "undefined" || sDomains.indexOf(sEnteredDomain.toLowerCase())==-1 ){

event.rc = false;

app.alert("Your email address must end with one of the following domains:  " + sDomains.join("\n"), 3);

}

})();

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
Participant ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

Duh!  So you set it up like an array, is that correct?  What does the -1 do in line 5?

Thank you sir!

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 ,
Oct 20, 2017 Oct 20, 2017

Copy link to clipboard

Copied

LATEST

Yes, I converted the sDomain string to an array, renamed it, and adjusted the rest of the code to work with it.

Regarding the -1, read this: JavaScript Array indexOf() Method

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