Jump to content

Multiple First Names and Initials Rule


GDP

Recommended Posts

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!

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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]";

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