views:

89

answers:

3

I've got a list of names which some code checks against to see if the person exists, and if so do some stuff..

My issue is that I want to handle the case of the name being entered incorrectly.. I.e. I have a list of names

Bob
Frank
Tom
Tim
John

If I type in Joohn, I want it to ask me if I meant John. If I type Tm, I get asked if I meant Tim, if I say no, it asks if i meant Tom.. Etc..

Has anyone done something like this before?

+5  A: 

If the name doesn't appear in the list, you can use algorithms like Levenshtein distance and Soundex to determine which entries in the list are closest and suggest those

Michael Mrozek
+1  A: 

The first thing would be to look in the list to see if you have an exact match. If not you calculate the Levenshtein distance between the word entered by the user and every element in the list. You suggest the one that has the lowest.

Darin Dimitrov
A: 

If you dont want to be limited to a list of people and want to search for common names you can use Google API service to submit spell check requests and receive in return a suggested spell correction for the query:

http://www.sitepoint.com/blogs/2004/03/10/check-your-spelling-with-google/

Luis