Jump to content

Checking email field for particular domain


Recommended Posts

Hi. I'm trying to come up with a rule that will look at the email field and see if it contains 'domain.com' and if it does not contain 'domain.com' to show an error. Any ideas? I feel like this is so close, yet so far.


The email address could be similar to these as well:





The idea is to limit this so gmail, yahoo and other random domains are not used. Thanks!


Here is the rule so far:


uEmail = Field("Email");


if('uEmail'.indexOf('domain.com') > -1);

{ return '<para style="(no style)"><f name="Arial"><z newsize="7.0">' +

"Must contain 'domain.com'. Please adjust or call support." + '</para>';}




x = Trim(Field("Email")).length;


if (x > 32)

return "<z newsize=7>" + Trim(Field("Email"));


return "<z newsize=7.5>" + Trim(Field("Email"));



Link to comment
Share on other sites

If 'domain.com' is not found in 'uEmail', then indexOf would return -1. If it is found, indexOf will return the position in the string at which it's found (0 - length of uEmail). So, if you want to return the error when 'domain.com' is not found, you need to modify your if statement to return the error if the indexOf is equal to -1 or when it is less than zero.


Also, by putting 'uEmail' in quotes, you're searching the string "uEmail" rather than the variable you've assigned the value of the "Email" field to. Obviously, "domain.com" is not found in "uEmail," so it will always return the error. You just need to modify it a bit:

if(uEmail.indexOf('domain.com') < 0)
{ return '<para style="(no style)"><f name="Arial"><z newsize="7.0">' +
"Must contain 'domain.com'. Please adjust or call support." + '</para>';


Just as a side note, resizing text based on character count can be a (somewhat) risky move unless you're using a fixed-width font. For example: "will" has the same number of letters as "been" but "been" is wider. You might want to look into using the "CopyfitLine" function like so:

var uEmail = Trim(Field("Email"));
var frameWidth = 72; // 72 points == 1 inch

if(uEmail.indexOf('domain.com') < 0)
   uEmail = "Must contain 'domain.com'. Please adjust or call support.";

return CopyfitLine("", uEmail, "Arial", 7.5, frameWidth, 7);

Link to comment
Share on other sites

That second line should be:

if (uEmail.indexOf('@domain.com') < 0)

Note that you need to use the uEmail variable, not a string with the value 'uEmail'. Also, you definitely don't want a semicolon right after the "if" condition. And I would put the @ symbol in to make sure it's actually a valid email address with domain.com at the end.


Or you could do this instead:

if (!uEmail.match(/@domain.com$/))


Farther down in the rule, you don't want to use <para> tags; those are only for FusionPro's internal use. You should use either <p> or <br> for a new line. But I don't think you need a newline at all in this case.


So I would use this for the whole rule:

var uEmail = Trim(Field("Email"));
if (!uEmail.match(/@domain.com$/))
   return '<f name="Arial"><z newsize="7.0"><color name="Red">' +
       "Email must end with '@domain.com'. Please adjust or call support.";

if (uEmail.length > 32)
   return "<z newsize=7>" + uEmail;
return "<z newsize=7.5>" + uEmail;

Although you might consider using CopyfitLine or CopyfitEmail at the end instead of relying on the length of the email address in characters, because unless you're using a monospace font, the width of each character can vary.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...