hi fellas,

need some brilliant idea, i want to get the firstname,lastname,middlename of
the employee below using javascript.
________________________
Atty.Jan Rex Camvarijan
Rex Uy Cambarijan
Rex Cambarijan
Rex
Ma.Rex B. Cambarijan |||
Rex del Rosario
__________________________

what i really want is how could i separate lastname firstname middlename in those diffirent structuce of name

thanks, =)

Recommended Answers

All 3 Replies

I don't know if you can do this, using the existing format. You could probably divide names up by line breaks, but then dividing names into first, middle, and last names would be difficult. You would have to require users to input the names in a particular format. Otherwise, the program has no way to know if a first name is, say, "Ma. Rex" or just "Ma." Or if the last name is "Cambarijan" or "III".

How is this input coming in to the program? From a textarea box? Text boxes?

Assuming line break is between each name.
1)separate each name using line break delimiter ==> A_LIST.split(/\r?\n/)
2)separate each of the name using white spaces ==> A_NAME.split(/\s+/)
3)determine what to go using the size of array after splitting
3.1)If the array size is 1, it is the first name (and may contain prefix)
3.2)If the array size is 2, the first element is the first name (and may contain prefix) and the second element is the last name
3.3)If the array size is 3, the first element is the first name (and may contain prefix), the second element may be the middle name or last name, and the third element may be the last name or suffix -- need to have your own mechanism to determine for suffix
3.4)If the array size is 4, the first element is the first name (and may contain prefix), the second element is the middle name, the third element is the last name, and the last element is the suffix
3.4.1)To determine middle name, last name, and prefix, may need to check only the third element whether it is a suffix
3.5)If the first element of the array ([0]) contains a period, split it. Then the first element of the split array is the prefix, and the second element is the first name

That's just a summary of how to do it. There are many other details but I can't show you right now because your information is limited.

thansk for the ideas....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.