PDA

View Full Version : Multiple First Names and Initials Rule


GDP
December 6th, 2013, 07:24 AM
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!

step
December 6th, 2013, 09:02 AM
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";

GDP
December 9th, 2013, 03:00 AM
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.

GDP
December 9th, 2013, 03:55 AM
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?

step
December 9th, 2013, 06:35 AM
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(/[\w-]*/i)[0].length>1) ? Field("First Name").match(/[\w-]*/i) : "your child";

David Miller
December 9th, 2013, 08:53 AM
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 (ToUpper(Field("FirstName")).match(/[\w-]*/i)[0].length>1) ? ToUpper(Field("FirstName")).match(/[\w-]*/i) : "YOUR CHILD";