Jump to content

Formatting Special Characters in Email Address


traba5058

Recommended Posts

I’m attempting to format the email address for a business card template and am stuck.

 

The database has an email address with First.Last.

 

My current rule is

 

if (Field("Individual Email") != "")
   return Field("Individual Email")+"@MyDomain.com"
   else return ""

 

I need assistance with the following:

 

1. Changing the . in the field & @MyDomain.com.com to Gotham Medium, 4.5pt with 5.4 pt leading

2. Change the @ symbol to Gotham Medium, 7pt with 8.4 pt leading

 

Any help with this will be much appreciated.

Link to comment
Share on other sites

I was working on an answer to your more complicated questions in this thread, but this is a lot simpler.

var s = TaggedDataField("Individual Email");
if (!s)
   return "";
//else
return s + '<span font="Gotham Medium" pointsize=7>@</span>MyDomain<span font="Gotham Medium" pointsize=4.5>.</span>com';

Regarding the leading, you shouldn't really need to do anything special in the rule for what you want. By default, you're automatically going to get 8.4 point leading for a line where the largest text is 7 point. If you need to adjust this, you can change the auto-leading factor in the Paragraph Formatting dialog.

 

Also, remember that everything on the same baseline has, by definition, the same leading between that baseline and the previous one, so you can't really have part of the email address with different leading than the rest.

 

Finally, you can certainly set the dot/period character to a different font and point size than the rest of the text, but I am skeptical that any human will be able to notice either a difference in the font or a small difference in point size for that particular character, which is just a single dot, after all.

Edited by Dan Korn
Changed to span tags to restore the previous point size as well as the font.
Link to comment
Share on other sites

Dan,

 

Thank you so much for your help on this. I was able to modify it and it works perfectly for the copy.

 

var s = TaggedDataField("Individual Email"); if (!s)
   return "";
//else
return s + '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>MyDomain</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';

 

I'm still having issues with the . in the Email field (First.Last). Any suggestions?

Link to comment
Share on other sites

Dan,

 

I don't know if I'm going about this right or not.

 

I created a new rule for the . in the Email field.

 

RuleEmail-1

return Field("Individual Email").replace(/\./gi, '<f name="Gotham Medium><new size="7">.</f>');

 

When I test with this rule, it works.

 

Can you tell me how to incorporate it into my other rule?

 

RuleEmail-2

var s = TaggedDataField("Individual Email"); if (!s)
   return "";
//else
return s + '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>SimpsonHousing</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';

Link to comment
Share on other sites

I created a new rule for the . in the Email field.

 

RuleEmail-1

return Field("Individual Email").replace(/\./gi, '<f name="Gotham Medium>[color="Red"]<new size="7">[/color].</f>');

 

When I test with this rule, it works.

It does? How does it work exactly? I'm confused. Because in your original post, you said:

1. Changing the . in the field & @MyDomain.com.com to Gotham Medium, 4.5pt with 5.4 pt leading

But in the rule above, it looks like you're trying to change the dot to 7 points, not 4.5.

 

Also, the tagging is wrong anyway. Instead of <new size="7"> you should be using the tag <z newsize=7>. If you compose and look at the log file, there will be an error message there saying that it doesn't recognize the tag named "new."

 

So your rule is not actually changing the point size at all. But even if it were changing the point size of the dot to 7, that's not what your stated requirement was. So again, exactly why do you think that it's working?

Can you tell me how to incorporate it into my other rule?

 

RuleEmail-2

var s = TaggedDataField("Individual Email"); if (!s)
   return "";
//else
return s + '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>SimpsonHousing</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';

Well, I'm not sure I understand exactly what you're trying to accomplish in that rule. When did the Telegrafico font become part of the requirements?

 

Frankly, I still don't understand why you want to change either the font or the point size of the dot (period) characters. How could that possibly make a difference that a person looking at the output could perceive? How would you be look at the output and know whether your dot was 4.5 points or 7, let alone whoever you're sending this output to?

 

That said, if you really think it will matter, I think this might do what you want:

var s = TaggedDataField("Individual Email");
if (!s)
   return "";
//else
var result = s.replace(/\./g, '<f name="Gotham Medium><z newsize=4.5>.</f>');
result += '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>SimpsonHousing</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';
return result;

Although I still am confused about the requirement. Can you post an example of the current output, and an example of the desired output, and a detailed explanation of what the differences are? Also, specify exactly what the font and point size of each character should be, including the ones that are not being modified by the rule.

Link to comment
Share on other sites

I agree with Dan that setting the leading on individual characters that (I'd imagine) you'd want to stay on the same line, is kind of pointless – so I excluded it from my code. Aside from that, you certainly don't need two JavaScript rules to handle your scenario. In fact, you can do it all at once like this:

var email = Field("Individual Email");

// If email is empty, return nothing
if (!email) return '';

// Else: add the domain
email += '@MyDomain.com';

// Replace . and @
return email.replace(/[\.@]/g, 
function(s) {
   var size = s == '.' ? 4.5 : 7;
   return '<span font="Gotham Medium" pointsize="' + size + '">' + s + '</span>';
});

Edited by step
Link to comment
Share on other sites

Dan & Stephen,

 

I'm sorry for my confusion. I've been using FusionPro for a while now but I haven't run into this situation before.

 

This customer has about 60 different business card layouts and I'm finding out that they care changing font (family, size, etc.) for specific characters within a field for more and more of them. If I get the FusionPro templates working, pre-press will not have to manually typeset each card when ordered.

 

The business card uses Telegrafico 9pt. This font is all caps and has no numbers or special characters. The customer uses Gotham Medium for numbers and special characters. Gotham Medium is a larger font, so the copy has to be reduced to 7pt.

 

Forum-BC.pdf is the PDF file from In Design.

 

I took your (Dan's) advice to use 7pt for all Gotham Medium including . rather than reducing it further.

 

When I used your original rule, it changed the font size for Telegrafico text too. So, I updated it to include the font information for the Telegrafico text. I was having trouble just changing the font size for that text, so I added the font name & it worked.

 

var s = TaggedDataField("Individual Email"); if (!s)
   return "";
//else
return s + '<f name="Gotham Medium"><z newsize=7>@</f><f name="Telegrafico"><z newsize=9>MyDomain</f><f name="Gotham Medium"><z newsize=7>.</f><f name="Telegrafico"><z newsize=9>com</f>';

 

The email field is formatted as First.Last. Using the above rule, the . from that field does not match correctly. See ForumBC-Output.pdf. You can also see the font size difference in this PDF with address.

 

return Field("Address").replace(/(\d+)/g,'<f name="Gotham Medium"><z newsize="7">$1</f>');

 

The above rule changes the font size for the Telegrafico text too.

 

Right now, I do not have a font formatting rule for the phone & fax. I simply put the format rule in the text frame, highlighted it and selected the font & size.

 

I'm trying to format all of these fields:

 

1.) Phone & Fax Numbers with Tags

2.) . and @ for email

3.) Numbers in address

 

I split the above formatting into two posts (you & Stephen have responded to both) and am trying to incorporate parts from both posts as well as posts from other people to get this to work.

 

On another card, I have to change the email field to upper case, add @MyDomain.com in upper case and change the @ symbol to 7pt.

 

I have 3 rules & they aren't working together. Rule 3 is the one I have in the template and it's not changing the font size for the @.

 

Rule 1

var Var1 = "Individual Email";
var CaseSelection = "allcaps";



if(CaseSelection == "allcaps")
return ToUpper(Field(Var1));

if(CaseSelection == "smallcaps")
return "<smallcap>" + Field(Var1) + "</smallcap>";

if(CaseSelection == "propercase")
return ToTitleCase(Field(Var1));

if(CaseSelection == "lowercase")
return ToLower(Field(Var1));

 

Rule 2

if (Rule("RuleEmailCase") != "")
   return Rule("RuleEmailCase")+"@SIMPSONHOUSING.COM"
   else return ""

 

Rule 3

return Rule("RuleEmail-1").replace(/(\@)/g, '<pointSize=7>@</pointSize>');

 

Thanks for all of your help!

Forum-BC.pdf

ForumBC-Output.pdf

Link to comment
Share on other sites

I took your (Dan's) advice to use 7pt for all Gotham Medium including . rather than reducing it further.

 

Cool, that makes it even simpler:

var email = Field("Individual Email");

// If email is empty, return nothing
if (!email) return '';

// Else: add the domain
email += '@MyDomain.com';

// Replace . and @
return email.replace(/([\.@])/g,'<span font="Gotham Medium" pointsize="7">$1</span>');

 

When I used your original rule, it changed the font size for Telegrafico text too. So, I updated it to include the font information for the Telegrafico text. I was having trouble just changing the font size for that text, so I added the font name & it worked.

That's because when you set the size with "z" tags – there is no closing z tag. Meaning you'll have to set the font back to whatever it originally was instead of just closing the tag. From the looks of the code you've posted, that's what you've done. It really doesn't have anything to do with setting the font as well:

var s = TaggedDataField("Individual Email"); if (!s)
   return "";
//else
return s + '<f name="Gotham Medium">[color="Red"]<z newsize=7>[/color]@</f><f name="Telegrafico">[color="red"]<z newsize=9>[/color]MyDomain</f><f name="Gotham Medium">[color="red"]<z newsize=7>[/color].</f><f name="Telegrafico">[color="red"]<z newsize=9>[/color]com</f>';

 

One of the advantages to using the span tag is that it allows you to set attributes within one tag and close them without having to reset prior attributes.

The email field is formatted as First.Last. Using the above rule, the . from that field does not match correctly. See ForumBC-Output.pdf. You can also see the font size difference in this PDF with address.

 

return Field("Address").replace(/(\d+)/g,'<f name="Gotham Medium"><z newsize="7">$1</f>');

 

The above rule changes the font size for the Telegrafico text too.

Again, that's because there is no closing z tag. You'd have to write it like this:

return[color="red"] '<f name="Telegrafico">' +[/color] Field("Address").replace(/(\d+)/g,'<f name="Gotham Medium"><z newsize="7">$1</f>[color="red"]<z newsize="9">[/color]');

 

Or, you know, with a span tag:

return Field("Address").replace(/(\d+)/g, '<span font="Gotham Medium" pointsize="7">$1</span>');

Right now, I do not have a font formatting rule for the phone & fax. I simply put the format rule in the text frame, highlighted it and selected the font & size.

 

I'm trying to format all of these fields:

 

1.) Phone & Fax Numbers with Tags

2.) . and @ for email

3.) Numbers in address

 

I split the above formatting into two posts (you & Stephen have responded to both) and am trying to incorporate parts from both posts as well as posts from other people to get this to work.

 

On another card, I have to change the email field to upper case, add @MyDomain.com in upper case and change the @ symbol to 7pt.

 

I have 3 rules & they aren't working together. Rule 3 is the one I have in the template and it's not changing the font size for the @.

 

Rule 1

var Var1 = "Individual Email";
var CaseSelection = "allcaps";



if(CaseSelection == "allcaps")
return ToUpper(Field(Var1));

if(CaseSelection == "smallcaps")
return "<smallcap>" + Field(Var1) + "</smallcap>";

if(CaseSelection == "propercase")
return ToTitleCase(Field(Var1));

if(CaseSelection == "lowercase")
return ToLower(Field(Var1));

 

Rule 2

if (Rule("RuleEmailCase") != "")
   return Rule("RuleEmailCase")+"@SIMPSONHOUSING.COM"
   else return ""

 

Rule 3

return Rule("RuleEmail-1").replace(/(\@)/g, '<pointSize=7>@</pointSize>');

 

Thanks for all of your help!

 

Is it correct to assume that Rule1 feeds to Rule2 and Rule 2 feeds to Rule 3? Is the domain name ("@SIMPSONHOUSING.COM") supposed to be all caps regardless of the "CaseSelection" applied in Rule 1? Also note that "pointsize" is not a tag. So you'd need to re-write that to use z tags or span tags – both topics which I've beaten to death already in this post.

 

Have you given the code I posted a try? It seems like it would have solved a lot of your problems. But just to clarify, I'm suggesting that you condense your 3 rules into one:

var email = Field("Individual Email");
// If email is empty, return nothing
if (!email) return '';

var CaseSelection = 'allcaps';
switch(CaseSelection){
 case 'allcaps':
   email = ToUpper(email);
   break;
 case 'smallcaps':
   email = '<smallcaps>' + email + '</smallcaps>';
   break;
 case 'lowercase':
   email = ToLower(email);
   break;
 default:
   email = email;
}

// Else: add the domain
email += '@SIMPSONHOUSING.COM';

// Replace . and @
return email.replace(/([\.@])/g,'<span font="Gotham Medium" pointsize="7">$1</span>');

 

Or if you want the domain of the email address to be affected by the CaseSelection:

var email = Field("Individual Email");
// If email is empty, return nothing
if (!email) return '';
email += '@SIMPSONHOUSING.COM';

var CaseSelection = 'allcaps';
switch(CaseSelection){
 case 'allcaps':
   email = ToUpper(email);
   break;
 case 'smallcaps':
   email = '<smallcaps>' + email + '</smallcaps>';
   break;
 case 'lowercase':
   email = ToLower(email);
   break;
 default:
   email = email;
}

// Replace . and @
return email.replace(/([\.@])/g,'<span font="Gotham Medium" pointsize="7">$1</span>');

 

Or if you'd rather keep all of your rules as is, you could create a global function that replaces everything that isn't a letter or space (essentially replacing only special characters) and call it from your respective rules:

 

JavaScript Globals

function ReplaceSpecial(text, font, size) {
   var font = font || 'Gotham Medium';
   var size = size || '7';
   return text.replace(/([^a-z|<>|\s]+)(?!([^<]+)?>)/gi,
       '<span font="' + font + '" pointsize="' + size + '">$1</span>');
}

return (Rule("RuleEmailCase")) ? ReplaceSpecial(Rule("RuleEmailCase")+"@SIMPSONHOUSING.COM") : '';

 

You could optionally specify a different font and pointsize for special use cases:

var twitter = '<span font="Telefico" pointsize="9">' + '@twitter';
return ReplaceSpecial(twitter, 'Arial Bold', 9); 
/*
Returns:
<span font="Telefico" pointsize="9"><span font="Arial Bold" pointsize="9">@</span>twitter

Note that numbers and special characters within tags are not replaced.
The @ sign (originally set to Telegrafico) is overridden by the function and changed to Arial Bold
*/

Edited by step
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.

Guest
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...