PDA

View Full Version : How to extract LastName, Firstname and Middle Initial from a Name


Jyoti
05-29-2003, 03:41 PM
I have a Name Field which has LastName, Firstname MiddleInitial

For eg: Name = Smit, William S

How can I separate the Last Name and place in a field of Lastname , Firstname in the Field of Firstname and Middle Initial in the Field Of Middle Initial on the ONLoad event of the Form.

Please help.

Is there a Left Function or a Left Property how to do it.

Thanks,
jyoti

Danne
05-29-2003, 04:24 PM
try this:

var name = "Smit, William S";
name = name.split(" ");
var lastName = name[0].slice(0,name[0].length-1);
var firstName = name[1];
var middleInitial = name[2];

Philip M
05-29-2003, 07:00 PM
But what about names like

van Amsterdam
de Lorean
de la Salle

liorean
05-29-2003, 07:14 PM
You can't cover all cases without having either a strict separator for it, that all name entries use, or using multiple fields in the first place. The multiple fields approach is often best, since names are very diverse in their structure. It's still not good enough, though.

For example, one of the guys in my student corridor has a single name consisting of a family name part and a person name part. You have no idea how much trouble that causes with most forms etc. where you are required to enter them separate, or how to handle it in the University databases.

Spookster
05-29-2003, 07:15 PM
You should really just use seperate form fields for first name, middle name and last name. As Phillip pointed out there is not one format that all names fit into. By using one form field you will also run into the problems like:

What if they Typed:

John Doe Sr.
John Foo Doe Jr.
Jon Foo van Doe Sr.

The point is you don't know what a person might type into that one field which allows for too many possiblities.

The only solution is to use a seperate field for each single piece of information that you need.