Copy link to clipboard
Copied
Hello!
I am creating an auto-fill PDF sheet that requires information to be repeatedly filled in various locations across the packet. It is to be filled in with client info, and in this specific case, their name.
I currently am using a text field "Full Name" where they enter first and last. I have a second text field "First Name" that extracts their first name and another for their last name using a field "Last Name." Their are various locations they would need to fill in their full name and then their first and last separately.
I am using this calculation script to extract their first and last to the separate fields I named above:
event.value = this.getField("First.Names").valueAsString.split(" ")[0];
I'm just wondering how I could use this script to also extract last names that include prefixes, so if their full name is Vincent van Gogh, the last name field will be populated with van Gogh instead of just Gogh.
Any help is appreciated! Thanks!
Copy link to clipboard
Copied
There's no way to do that with 100% accuracy. You'll be better off letting people enter their own names separately.
Copy link to clipboard
Copied
So how exactly do you know the last name has a prefix when you look at a full name? Think about it. You need an AI for that.
Try67's suggestion is the correct answer. Make them enter the last name separately.
Copy link to clipboard
Copied
All the above suggestion are correct, however if you really want to do it the way you describe it, and you think that will work for you, use this:
var str = this.getField("First.Names").valueAsString.split(" ");
if(str.length == 3)
event.value = str[1]+" "+str[2];
else if(str.length == 2)
event.value = str[1];