GDP Posted December 6, 2013 Share Posted December 6, 2013 Hi Guys, I have a job where a child's name is entered into a paragraph of text. However, in the data supplied some of the first names have two names and others only have an initial. Is there a rule I can write where if the field 'First Name' contains more than one name ie; 'Cyril George', then it will return just the first name = 'Cyril'. Can this rule also look for initials within that same field and return 'your child'? I've been beavering away at this and getting nowhere. Any help would be much appreciated! Quote Link to comment Share on other sites More sharing options...
step Posted December 6, 2013 Share Posted December 6, 2013 I guess you could write something returned the value of the "First Name" field until it got to a space so that "Cyril George" would just return "Cyril." Like this: return Field("First Name").match(/\w*/i); I'm not sure what you're looking for as far as initials go, but you could modify the above code to measure the field to see if it's longer that 1 character, like so: return (Field("First Name").match(/\w*/i)[0].length>1) ? Field("First Name").match(/\w*/i) : "your child"; Quote Link to comment Share on other sites More sharing options...
GDP Posted December 9, 2013 Author Share Posted December 9, 2013 Thanks for getting back to me with a solution on this step. I'm very new to this. I've been using FusionPro for years starting with DL100! But I've never really delved under the bonnet and set up rules etc. Quote Link to comment Share on other sites More sharing options...
GDP Posted December 9, 2013 Author Share Posted December 9, 2013 How do I get this to also include all names if there is a hyphen? For example; Marie-Ann? At the moment it is returning Marie... Also, I'm trying to set up this rule for a paragraph that is all caps - I've created an AllCaps rule using the wizard, but I'm having trouble applying it to a rule? Is this possible? Quote Link to comment Share on other sites More sharing options...
step Posted December 9, 2013 Share Posted December 9, 2013 The regex that I used ("\w") is looking for a string of alphas. You can modify it to search for a string of alphas or hyphens by putting them between brackets ("[]") like this: return (Field("First Name").match(/[color="red"][\w-]*[/color]/i)[0].length>1) ? Field("First Name").match(/[color="Red"][\w-]*[/color]/i) : "your child"; Quote Link to comment Share on other sites More sharing options...
David Miller Posted December 9, 2013 Share Posted December 9, 2013 To achieve all caps in Step's rule: Also, I'm trying to set up this rule for a paragraph that is all caps - I've created an AllCaps rule using the wizard, but I'm having trouble applying it to a rule? Is this possible? return ([color="Red"]ToUpper([/color]Field("FirstName")[color="red"])[/color].match(/[\w-]*/i)[0].length>1) ? [color="red"]ToUpper([/color]Field("FirstName")[color="red"])[/color].match(/[\w-]*/i) : "[color="red"]YOUR CHILD[/color]"; 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.