wptucson Posted August 11, 2015 Share Posted August 11, 2015 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: first@domain.com first@email.domain.com first@sub.domain.com 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")); else return "<z newsize=7.5>" + Trim(Field("Email")); } Quote Link to comment Share on other sites More sharing options...
step Posted August 11, 2015 Share Posted August 11, 2015 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); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted August 11, 2015 Share Posted August 11, 2015 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; //else 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. Quote Link to comment Share on other sites More sharing options...
wptucson Posted August 11, 2015 Author Share Posted August 11, 2015 Yay! It worked. Thank you both! Thank goodness for this forum or I'd really be lost. I feel like I need remedial programming lessons...I went to school for marketing not computer science. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.