Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments
SOLVED

Text Wild Card

Avatar

Level 9

I want to write a script to verify the user entered their company email address correctly. The only part of the email address I can verify is the last section (@companyname.com), Is there a text wild card that I can use that represents and amount of text so I can verify the last section of the address, like *:

If(emailaddress.rawValue !== *@companyname.com){

xfa.host.msgbox("Last part of your email address is not correct");

}

1 Accepted Solution

Avatar

Correct answer by
Level 10

Here you go


var str = Textfield1.rawValue;



if (!str.match(/^([a-zA-Z0-9\-\_\.]+)@(domain1|domain2).com$/gm)) {


  xfa.host.messageBox("The E-Mail-Address in not correct …");


}


View solution in original post

4 Replies

Avatar

Level 10

Hi,

you can use a regular expression to test the email-addresses.


var str = Textfield1.rawValue;



if (!str.match(/^([a-zA-Z0-9\-\_\.]+)@yourdomain.com$/gm)) {


  xfa.host.messageBox("The E-Mail-Address in not correct …");


} else {


    // Script to execute otherwise …


}


Hope this helps.

Avatar

Level 9

radzmar,

Your script works great but I have two company domains that I have to compair to what the user enters. In other words they have to enter either myname@domain1.com or myname@domain2.com. If it is neither of these then the error message pops-up. I tried to modify your script to accomdate this but cannot get it to work.



var str = this.rawValue;

if ((!str.match(/^([a-zA-Z0-9\-\_\.]+)@yourdomain.com$/gm))||(!str.match(/^([a-zA-Z0-9\-\_\.]+)@yf.com$/gm))) {

  xfa.host.messageBox("The E-Mail-Address in not correct …");

  }

Avatar

Correct answer by
Level 10

Here you go


var str = Textfield1.rawValue;



if (!str.match(/^([a-zA-Z0-9\-\_\.]+)@(domain1|domain2).com$/gm)) {


  xfa.host.messageBox("The E-Mail-Address in not correct …");


}