Jump to content

Change color of "@" symbol


Recommended Posts

I'm having trouble writing a rule to change the color of the "@" symbol to black while keeping the rest of the email address red. When I validate the rule it returns my field correctly but it is not changing the color when I preview it. I have checked and I labeled the color exactly how it is spelt in my loaded colors and I have "treat returned strings as tagged text" selected. What am I missing? Thanks!

 

return Field("Email").replace(/@/g, '<color name="Black">@</color>');

Edited by hkenney
Link to comment
Share on other sites

I'm having trouble writing a rule to change the color of the "@" symbol to black while keeping the rest of the email address red. When I validate the rule it returns my field correctly but it is not changing the color when I preview it. I have checked and I labeled the color exactly how it is spelt in my loaded colors and I have "treat returned strings as tagged text" selected. What am I missing? Thanks!

 

return Field("Email").replace(/@/g, '<color name="Black">@</color>');

 

Hmmm. Your rule works for me. Are you sure you are inserting the rule into your text frame and not the Field Email?

 

You could also try escaping the ampersand, but I don't think it is necessary. This works for me as well.

 

return Field("Email").replace(/[color="Red"]\[/color]@/gi, '<color name="black">@</color>');

Edited by David Miller
Link to comment
Share on other sites

Thanks for looking into this David! Yes I am inserting the rule into the text field. I have been trying and trying and nothing is working. Could it be because the red color in the rest of the string is a spot color? I can't see why that would matter but I'm trying to think of anything!

 

Thanks,

 

Hilary

Link to comment
Share on other sites

Hmmm. Your rule works for me. Are you sure you are inserting the rule into your text frame and not the Field Email?

Hilary, I think what David is saying here is that maybe you're inserting your "Email" field into your text frame as opposed to the rule you used to manipulate your "Email" field. You can change your rule to something like this to make sure your template is pulling in the correct rule:

return "Yep, I'm the Email rule!";

 

I agree that your rule looks like it should work. We'd probably have to see your actual template to get a better idea of what's happening. That being said, another thing you could try is using span tags rather than color tags:

return Field("Email").replace('@','<span color="Black">@</span>');

Link to comment
Share on other sites

Okay well now I understand. The rule in your template is not the same as the rule that you posted to the forum. The rule in your template is missing the "name" property for the "color" tag and it's looking for the HTML entity of the '@' symbol rather than the '@' symbol itself:

return Field("Email").replace(/[color="red"]& # 6 4 ;[/color]/g, '[color="Red"]<color ="Black">& # 6 4 ;[/color]</color>');

Since your data isn't passing the "@" as the HTML entity, there's no reason to search for it in that field. So ironically, if I change your rule to match the code in your original post (after the forum converted the entity to the @ symbol), I get the desired result:

return Field("Email").replace(/@/g, '<color name="Black">@</color>');

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