Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create accent insensitive search 1

Status
Not open for further replies.

hardingd

Programmer
Dec 5, 2005
3
CA
Hi everyone,
I would firstly like to say hello to everyone as this is my first time at tek-tips.com.
I'm making a dynamic popup of user names as the user is entering them. I was wondering if anyone had any tips for making an accent insensitive search using javascript.
Here's my setup:
Code:
for(i = 0; i < arrName.length; i++)
{
if([b]arrName[i].toLowerCase().indexOf(searchValue)[/b] == 0 && searchValue.length != 0)
{
	fillBox.innerHTML += '<div class="peopleSearch" >+ arrName[i] + '</div>';
results ++;
}
}
My issue is that if people don't enter the accented charater, they won't get the results that have accented characters such as ê and é.
Does anyone have any suggestions?
Thanks in advance,
HardingD
 

Another way (but possibly a little inefficient) would be to hold an array of the character codes that are related.. e.g. é É e E - you would probably create an associative array which stored each character or character code as the reference and the preferred basic character as the value... e.g.:

aChars['é'] = 'e';
aChars['e'] = 'e';
or
aChars['233'] = 'e';
etc

And then to pre-parse any text you want to compare using a function that replaces any 'exotic' char with it's basic equivalent - so café would become cafe etc etc.

There may be some built in method/parameter but if there is it escapes me at the moment.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Hey guys,
Thanks for the response. I think I'm going to have to use a couple of arrays for this as damber suggested.
I don't think it will be that inefficient becuase it will only take two or three key presses to limit the result set to what the user wants.
Much appreciated.
HardingD.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top